Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Write a function remove_duplicates that takes in a list and removes elements of the list that are the same.
- The order in which you present your output does not matter.
- Do not modify the list you take as input! Instead, return a new list.
- '''
- # Solution 1
- def remove_duplicates(list_dup):
- count_list = set(list_dup)
- return list(count_list)
- print remove_duplicates([1, 1, 2, 2])
- # Solution 2
- def remove_duplicates(list_dup):
- new_list =[]
- for item in list_dup:
- if item not in new_list:
- new_list.append(item)
- return new_list
- print remove_duplicates([1, 1, 2, 2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement