💡 Python Life Hack: Do you know you can copy the files from a computer to a mobile phone 📱 without any cable using Python 🐍 ?
@Python_Codes
@Python_Codes
Python Class Anatomy
Almost everything a Python class definition can contain summed up in one image :)
@Python_Codes
Almost everything a Python class definition can contain summed up in one image :)
@Python_Codes
Python Tip:
You can use dict o
@Python_Codes
You can use dict o
n a clas
s instance to get all instance attributes as a dictionary@Python_Codes
Python Tip:
You can use the calendar module in one line from the command line with python -m calendar
@Python_Codes
You can use the calendar module in one line from the command line with python -m calendar
@Python_Codes
Most of the time, we don't want to share our wifi passwords, in that case, we generate a QR and stick it on the wall.
@Python_Codes
@Python_Codes
round() function
the round function is used to convert the floating-point into a specified number of decimals number
@Python_Codes
the round function is used to convert the floating-point into a specified number of decimals number
@Python_Codes
How do you check if an array is monotonic?
An array is monotonic if the elements are sorted either in descending order or ascending order.
Share and Support
@Python_Codes
An array is monotonic if the elements are sorted either in descending order or ascending order.
Share and Support
@Python_Codes
What are pure functions?
A pure function is a function that will return the same value given the same arguments. A function is not pure if there is something outside the function that can change its return value, given the same arguments.
Share and Support
@Python_Codes
A pure function is a function that will return the same value given the same arguments. A function is not pure if there is something outside the function that can change its return value, given the same arguments.
Share and Support
@Python_Codes
💡🐍 Did you know?
You can use slices in Python to insert elements to a list in arbitrary positions?
Share and Support
@Python_Codes
You can use slices in Python to insert elements to a list in arbitrary positions?
Share and Support
@Python_Codes
Common techniques for using the set() function in Python:
1. Create a set from a list:
@Python_Codes
1. Create a set from a list:
my_list = [1, 2, 2, 3, 3, 3]2.Add an item to a set:
my_set = set(my_list)
my_set = {1, 2, 3}3.Remove an item from a set by its value:
my_set.add(4)
my_set = {1, 2, 3}4.Check if an item is in a set:
my_set.remove(3)
my_set = {1, 2, 3}5.Get the length of a set:
if 3 in my_set:
print("The item is in the set.")
my_set = {1, 2, 3}6.Loop through the items in a set:
set_length = len(my_set)
my_set = {1, 2, 3}7.Get the union of two sets:
for item in my_set:
print(item)
set1 = {1, 2, 3}8.Get the intersection of two sets:
set2 = {3, 4, 5}
union_set = set1.union(set2)
set1 = {1, 2, 3}Share and Support
set2 = {3, 4, 5}
intersection_set = set1.intersection(set2)
@Python_Codes
Common techniques for using the zip() function in Python:
1. Zip two lists together:
@Python_Codes
1. Zip two lists together:
list1 = [1, 2, 3]2. Unzip a zipped list:
list2 = [4, 5, 6]
zipped_lists = zip(list1, list2)
zipped_lists = [(1, 4), (2, 5), (3, 6)]3. Loop through a zipped list:
list1, list2 = zip(*zipped_lists)
zipped_lists = [(1, 4), (2, 5), (3, 6)]4.Convert a zipped list to a dictionary:
for item1, item2 in zipped_lists:
print(item1, item2)
zipped_lists = [(1, 4), (2, 5), (3, 6)]5. Zip three or more lists together:
my_dict = dict(zipped_lists)
list1 = [1, 2, 3]Share and Support
list2 = [4, 5, 6]
list3 = [7, 8, 9]
zipped_lists = zip(list1, list2, list3)
@Python_Codes
The union of two sets can be found using the union() method.
Here is an example:
You can also use the | operator to find the union of two sets. For example:
Keep in mind that sets are unordered collections of unique items, so the order of the items in the union set may not be the same as the order of the items in the original sets.
Share and Support
@Python_Codes
Here is an example:
set1 = {1, 2, 3}This will create a new set called union_set that contains all of the items from set1 and set2. In this case, union_set will be equal to {1, 2, 3, 4, 5}.
set2 = {3, 4, 5}
union_set = set1.union(set2)
You can also use the | operator to find the union of two sets. For example:
set1 = {1, 2, 3}This will produce the same result as the union() method.
set2 = {3, 4, 5}
union_set = set1 | set2
Keep in mind that sets are unordered collections of unique items, so the order of the items in the union set may not be the same as the order of the items in the original sets.
Share and Support
@Python_Codes