So I’ve used a for loop to check for duplicates in the past but this time since I need to keep only the unique characters in the same order they were provided, I went with the dictionary route.
As you can see from the code below, however, it does not disregard case.
def duplicate_remover(stuff):
new_list = list(dict.fromkeys(stuff))
return new_list
duplicate_remover(['matt', 'bob', 'Matt', 'john', 'Matt',1,2,1,6,3,4,1,2])
# note this does not weed out duplicates which have different cases but does work for both integers and strings
So I tried to add a modification which would convert the items to a string and then lower case if the input is a string and if not them to skip that step but it doesn’t work if use “continue” or “break” and I don’t know how to tell it to skip it… and it gives me an empty list now
def duplicate_remover(stuff):
stuff = [x.lower() for x in stuff if x == str]
new_list = list(dict.fromkeys(stuff))
return new_list
duplicate_remover(['matt', 'bob', 'Matt', 'john', 'Matt',1,2,1,6,3,4,1,2])