top of page

finding duplicates with python

You can use the below python script to find where there are duplicates in a character set.


First open a Python IDLE shell window and enter this code:


>>> def find_duplicates(s):

elements = {}

for char in s:

if elements.get(char,None) != None:

elements[char]+=1

else:

elements[char] = 1

return [k for k,v in elements.items() if v>1]


Then enter the set of characters you want to search using the print command and the command created by this code

>>> print(find_duplicates("ATRZSWAPOS"))


After this is saved, Python will give you the result shown below.




Comments


bottom of page