5 Python tips and tricks that you not know
1. If you want to get a lot of things as an input just put split() at the end and Take many as input as needed just separate them by comma( ,)
x,y,z,p = input("give me number").split()
print(x)
print(y)
print(z)
print(p)
2 .If you have a lot of condition to be fulfill in that case you write the condition in a list and you have to use all and that how you make sure they all this condition will be fulfilled subs = 3000
likes = 300
comments = 100
conditions = [
subs >160,
likes>160,
comments>60
]
if all(conditions):
print('avesome vedio')
3 .If you have a lot of condition. You can put them in a list and if you fulfill atleast one you will still execute it subs = 2400
likes = 300
comments = 100
checkers = [
subs>2500,
likes>500,
comments>50
]
if any(checkers):
print('awesome video')
4. You can easily use set and list to remove all the duplicate here a = [1,2,3,4,2,5,6,2,3,8,5,9,10,23,45,3,]
print(a)
a = list(set(a))
print(a)
5 .To get the most repeated elements in a list use the set and use the key as the count and get the most a = [ 1,2,1,3,4,1,6,17,9,4,6,1,8,0,4,1,1,3,1,5,1,] print(a) most = max(set(a),key= a.count) print(most)
0 Comments