CODE:
-
list = ['one', 'two', 'three', 'one', 'one', 'four', 'two']
-
#convert the list into a set. An element can only exist once within a set
-
set = set(list)
-
#convert the set back into a list type
-
list = list(set)
-
print list
Are those variable names confusing? Let's look at that example again:
CODE:
-
fruits = ['apple', 'bananas', 'cantaloupes', 'apple', 'apple', 'durian', 'bananas']
-
#convert the list into a set. An element can only exist once within a set
-
fruits_unique = set(fruits)
-
#convert the set back into a list type
-
fruits = list(fruits_unique)
-
print fruits