Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Write a program (function!) that takes a list and returns a new list that
- # contains all the elements of the first list minus all the duplicates.
- # Write two different functions to do this - one using a loop and constructing
- # a list, and another using sets.
- # USING SETS
- def minus_duplicates(list):
- numbers = set(list)
- list2 = list(numbers)
- print(list2)
- a = [1, 1, 2, 3, 5, 7, 7, 8, 16, 13, 5]
- minus_duplicates(a)
- # USING A LOOP AND CONSTRUCTING A LIST
- def loop(list):
- nothing = []
- for i in list:
- if i not in nothing:
- nothing.append(i)
- print(nothing)
- a = [1, 1, 2, 3, 5, 7, 7, 8, 16, 13, 5]
- loop(a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement