|
| 1 | +# import collections |
| 2 | +# |
| 3 | +# l1 = [10, 20, 30, 40, 50] |
| 4 | +# l2 = [10, 20, 30, 50, 40, 70] |
| 5 | +# l3 = [10, 20, 50, 40, 30] |
| 6 | +# # Counter() function counts the frequency of the items in a list |
| 7 | +# # and stores the data as a dictionary in the format <value>:<frequency> |
| 8 | +# print(collections.Counter(l1)) # Counter({10: 1, 20: 1, 30: 1, 40: 1, 50: 1}) |
| 9 | +# print(collections.Counter(l2)) # Counter({10: 1, 20: 1, 30: 1, 50: 1, 40: 1, 70: 1}) |
| 10 | +# print(collections.Counter(l1) == collections.Counter(l2)) # False |
| 11 | +# # True , even if order is not same also matches |
| 12 | +# print(collections.Counter(l1) == collections.Counter(l3)) |
| 13 | +# print(set(l1)) #{40, 10, 50, 20, 30} |
| 14 | +# print(set(l3)) # {40, 10, 50, 20, 30} |
| 15 | +# l1.sort() |
| 16 | +# l3.sort() |
| 17 | +# print(l1 == l3) #True |
| 18 | +# |
| 19 | +# l1 = [10, 20, 30, 40, 50] |
| 20 | +# l3 = [50, 10, 30, 20, 40] |
| 21 | +# a=set(l1) |
| 22 | +# b=set(l3) |
| 23 | +# print(a,b) |
| 24 | +# print(a==b) |
| 25 | +# |
| 26 | +# |
| 27 | +# l1 = [-10, -20, 30, 40, 50] |
| 28 | +# l3 = [50, 75, 30, 20, 40, 69] |
| 29 | +# res = [x for x in l1+l3 if x not in l1 or x not in l3] |
| 30 | +# print(res) |
| 31 | +# new_list= [] |
| 32 | +# for item in l1: |
| 33 | +# pos = abs(item) |
| 34 | +# new_list.append(pos) |
| 35 | +# print(new_list) |
| 36 | + |
| 37 | +# x = set(['x1','rr','x3','y4']) |
| 38 | +# y = set(['x1','rr','rr','y4']) |
| 39 | +# |
| 40 | +# print ("List first: " + str(x)) |
| 41 | +# print ("List second: " + str(y)) |
| 42 | +# |
| 43 | +# # take difference of two lists |
| 44 | +# z = x.difference(y) |
| 45 | +# |
| 46 | +# print("Difference of first and second String: " + str(z)) |
| 47 | +# |
| 48 | +# number_list = [x for x in range(100) if x%3 == 0 if x%5 == 0] |
| 49 | +# print(number_list) |
| 50 | + |
| 51 | +my_list = ['91 9925479326', '18002561245', 'All the best', 'good'] |
| 52 | +print([i for i in my_list if not i.startswith(('91', '18'))]) # ['All the best', 'good'] |
0 commit comments