from collections import Counter s1 = 'below' s2 = 'elbow' print('anagram') if Counter(s1) == Counter(s2) else print('not an anagram')or we can also do this using the sorted() method like this.print('anagram') if sorted(s1) == sorted(s2) else print('not an anagram')
decimal = int('1010', 2) print(decimal) #10
'Hi my name is Allwin'.lower() # 'hi my name is allwin' 'Hi my name is Allwin'.casefold() # 'hi my name is allwin'
'hi my name is Allwin'.upper() # 'HI MY NAME IS ALLWIN'
'convert string to bytes using encode method'.encode() # b'convert string to bytes using encode method'
import shutil; shutil.copyfile('source.txt', 'dest.txt')
qsort = lambda l : l if len(l)<=1 else qsort([x for x in l[1:] if x < l[0]]) + [l[0]] + qsort([x for x in l[1:] if x >= l[0]])
sum(range(0, n+1))This is not efficient and we can do the same using the below formula.sum_n = n*(n+1)//2
a,b = b,a
lambda x: x if x<=1 else fib(x-1) + fib(x-2)]
联系客服