Python - No Looping for difference and removal of duplicate elements.
Getting difference between tuples
a = ('one',2,'three','five')
b = (2,'five','six')
c = tuple(set(a) - set(b)) # ('three','one')
Getting difference between list
a = ['one',2,'three','five']
b = [2,'five','six']
c = list(set(a) - set(b)) # ['three','one']
Getting difference between dictionary keys
a = {1:'one',2:'two',3:'three',5:'five'}
b = {2:'two',5:'five',6:'six'}
c = list(set(a.keys()) - set(b.keys())) # ['three','one']
Eliminating duplicate elements without looping:
a = [1,2,1,4,5,2]
b = list(set(a)) # [1,2,4,5]
Written by hemraj surti
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Related Tags
#python
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#