Remove_duplicates


#1


what is the difference between these two codes, why is the output different



#2

add a print statement after your for loop in your first function:

for Item in Items:
    print Item

see how Item contains the entire string? Your list only contains one item, a string

to solve this, on line 1 change the list so it contains multiply strings:

y = ["a","b","c","a"]

#3

ok so
def remove_duplicates(Items):
ItemsNoDuplicates=[]

for Item in Items:

    if Item not in ItemsNoDuplicates:

        ItemsNoDuplicates.append(Item)

return ItemsNoDuplicates

print remove_duplicates(["p","d","e","p"])
print remove_duplicates(["p,d,p,p"])

both the print statements are viewed differently by python.... it indexes the entire string as 1 in second print statement and seperately in first.
if i were to get printout of second i may have to loop the function again..or even split ...! the entire string with .split()


#4

you understand the difference? for ["p,d,p,p"], there is simply 1 item in the list (a string), the , are simply part of the string, and not separating elements in list, so yes, you would need split(",")


#5

yes.... i did thank you..


#6