# coding=utf-8
"""
 List Remove Duplicates
Exercise 14 (and Solution)

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.

Extras:

    Write two different functions to do this - one using a loop and constructing a list, and another using sets.
    Go back and do Exercise 5 using sets, and write the solution for that in a different function.

Discussion

Concepts for this week:

    Sets

Sets

In mathematics, a set is a collection of elements where no element is repeated. This becomes useful because if you know your data is stored in a set, you are guaranteed to have unique elements.
Features of sets

    Sets are not ordered. This means that there is no “first element” or “last element.” There are just “elements”. You cannot ask a set for it’s “next element”.
    There are no repeat elements in sets.
    You can convert between sets and lists very easily.

In Python

In Python, you make and use a set with the set() keyword. For example:

  names = set()
  names.add("Michele")
  names.add("Robin")
  names.add("Michele")
  print(names)

And the output will be;

  set(['Michele', 'Robin'])

You can do to a set almost anything you can do to a list (except ask for things like “the third element”). See the Python documentation about sets to get a full list of things you can do to sets.

You can convert from a list to a set and a set to a list pretty easily:

  names = ["Michele", "Robin", "Sara", "Michele"]
  names = set(names)
  names = list(names)
  print(names)

And the result of this will be:

  ['Michele', 'Robin', 'Sara']
"""

import random

def remove_duplicates_1(l):
    clear_list= []
    for i in l:
        if i not in clear_list:
            clear_list.append(i)
    return  sorted(clear_list)

def remove_duplicates_2(l):
    clear_list= set(l)
    return list(clear_list)



alist = []

for i in range(20):
    alist.append(random.randint(0,20))
print(sorted(alist))
print("Duplikátumok eltávolítása: ")
print(remove_duplicates_1(alist))

print("\n")
print(remove_duplicates_2(alist))