Hi Guys!!!!
Hope you all doing well!!!!.
Today I am going to discuss, Puthon must know resource. First Why python is so important?
Python is one of the world’s most popular, in-demand programming languages. This is for many reasons:
geopy
howdoi
Need to check StackOverflow, but don’t want to leave the terminal?
List comprehensions
Find memory used by an object
Find the most frequent element in a list
Calculate time taken to execute a piece of code
Use chained function call
Thanks
Saurabh Sharma
Happy Coding !!!
Hope you all doing well!!!!.
Today I am going to discuss, Puthon must know resource. First Why python is so important?
Python is one of the world’s most popular, in-demand programming languages. This is for many reasons:
- it’s easy to learn
- it’s super versatile
- it has a huge range of modules and libraries(known as Batteries)
You find all the example from my github page
https://github.com/Saurabh-12/Python_Learning
# all or any
You want to plot graphs in the console ?
# all or any
x = [True, True, False] if any(x): print("At least one True") if all(x): print("Not one False") if any(x) and not all(x): print("At least one True and one False")bashplotlib
You want to plot graphs in the console ?
pip install bashplotlib
collections
Python has some great default datatypes and collection . You can check it from my github page.
https://github.com/Saurabh-12/Python_Learning/blob/master/Python_Collections.py
collections
Python has some great default datatypes and collection . You can check it from my github page.
https://github.com/Saurabh-12/Python_Learning/blob/master/Python_Collections.py
from collections import OrderedDict, Counter
# Remembers the order the keys are added!
x = OrderedDict(a=1, b=2, c=3)
# Counts the frequency of each character
y = Counter("Hello World!")
print(y)
print(x)
emoji
Yes, really
Yes, really
pip install emoji
from emoji import emojize
print(emojize(":thumbs_up:"))
geopy
It works by abstracting the APIs of a range of different geocoding services. It enables you to obtain a place’s full street address, latitude, longitude, and even altitude.
pip install geopy
from geopy import GoogleV3
place = "Manjunatha Layout,Munnekolala,Marathali, Bangalore, India"
location = GoogleV3().geocode(place)
print(location.address)
print(location.location)
howdoi
Need to check StackOverflow, but don’t want to leave the terminal?
pip install howdoi
howdoi for loop in python
**kwargs
The double-asterisk in front of a dictionary object lets you pass the contents of that dictionary as named arguments to a function.
dictionary = {"a": 1, "b": 2}
def someFunction(a, b):
print(a + b)
return
# these do the same thing:
someFunction(**dictionary)
someFunction(a=1, b=2)
One of the best thing in python. Check my git hub page check dedicatd example
map
Python supports functional programming through a number of inbuilt features.
One of the most useful is the map() function — especially in combination with lambda functions.
zip
Ever needed to form a dictionary out of two lists?
keys = ['a', 'b', 'c']
vals = [1, 2, 3]
zipped = dict(zip(keys, vals))
print(zipped)
Virtual environments
Let say we are working on multiple Python projects at any one time.
Unfortunately, sometimes two projects will rely on different versions of the same dependency.
Which do We install in our system?
To solve this :- venv is solution for this . For more detail see my blogs dedicaed to it
uuid
A quick and easy way to generate Universally Unique IDs (or ‘UUIDs’) is through the Python Standard Library’s uuid module.
import uuid
user_id = uuid.uuid4()
print(user_id)
pprint
Python’s default print function does it work quite good.
But if We try to print out any large, nested object, and the result is rather ugly.
pprint comes to rescue us for printing out complex structured objects in an easy-to-read format.
import requests
import pprint
url = 'https://randomuser.me/api/?results=1'
users = requests.get(url).json()
pprint.pprint(users)
import sys
print(sys.getsizeof(5)) # 28
print(sys.getsizeof("Python")) # 55
def most_frequent(list):
return max(set(list), key = list.count)
numbers = [1, 2, 3, 2, 4, 3, 1, 3]
print(most_frequent(numbers)) # 3
import time
start_time = time.time()
a,b = 5,10
c = a+b
end_time = time.time()
time_taken = (end_time- start_time)*(10**6)
print("Time taken in micro_seconds:", time_taken)
# Time taken in micro_seconds: 3.89577484130859375
Find unique characters in a string
string = "abcbcabdb"
unique = set(string)
new_string = ''.join(unique)
print(new_string) # abcd
def add(a, b):
return a + b
def subtract(a, b):
return a - b
a, b = 5, 10
print((subtract if a > b else add)(a, b)) # 15
Saurabh Sharma
Happy Coding !!!
This comment has been removed by the author.
ReplyDeleteNice 4 Hi Printing Machine Manufacturers blog and I will share to my friends. Also I suggest 4 Hi Printing Machines .
ReplyDeleteThe front end is developed utilizing front end friendly technologies like HTML5, CSS3, Jquery, Javascript. APTRON Gurgaon from Gurgaon offers you full stack training for all these front end technologies with the help of our top IT professionals.
ReplyDeleteFor More Info: Full Stack Course in Gurgaon
Pressure Wash CO is a Professional Pressure Washing Company based on Gold Coast and its suburbs. We provide different types of services based on Commercial and Residential Services. We do High Pressure Cleaning Gold Coast.
ReplyDelete