14/15 code not working for list of strings?


#1

Here's my code:

def remove_duplicates(raw):
    new=[]
    for i in raw:
        if i not in new:
            new.append(i)
    return new
remove_duplicates (['new', 'new', 'old', 'old'])

interesting thing is the code worked fine for list of integers, but returns 'none' when tried it with above list of strings. and apparently the code checker didn't consider that scenario so I still passed :smirk: Would appreciate any input to get it to work with list of strings, thanks!


#2

@terarockstar65319 it does work for strings. you have to call the function like this

print remove_duplicates (['new', 'new', 'old', 'old']) # ['new', 'old']
``` 
remember when you wrote this for loop
```
for i in raw:

the interpreter creates an iterator over the elements in the list in the list.This iterator will be the same type as the elements in your list.So when your list is made up strings then i will be a string at each step of the iterator, likewise if they were integers


#3

That's right, thanks! Can't believe I forgot the print statement in the end :laughing: