Advertisement
elena1234

Find Duplicates ( in Python )

Jan 21st, 2022 (edited)
772
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. some_list = ['a', 'b', 'c', 'b', 'd', 'm', 'n', 'n']
  2. some_dictionary = {}
  3.  
  4. for element in some_list:
  5.     if element not in some_dictionary:
  6.        some_dictionary[element] = 1
  7.     else:
  8.         some_dictionary[element] += 1
  9.  
  10. for key, value in some_dictionary.items():
  11.     if value > 1:
  12.        print(key, end = ' ')
  13.  
  14. # another way
  15. duplicates = []
  16.  
  17. for x in some_list:
  18.     if some_list.count(x) > 1 and x not in duplicates:
  19.         duplicates.append(x)
  20.        
  21. print()
  22. print(duplicates)
  23.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement