Define a function that removes duplicates from an array of numbers and returns it as a result.

The order of the sequence has to stay the same.

Difficulty: introductory

Starter code:

def distinct(seq):
	

Solutions:
def distinct(seq):
    return sorted(set(seq), key = seq.index)

def distinct(seq):
    result = []
    seen = set()
    for a in seq:
        if a not in seen:
            result.append(a)
            seen.add(a)
    return result

# Using Set:
# Time complexity | O(N)
def distinct(seq):
    result = []
    seen = set()
    for a in seq:   #O(N) operation in terms of time complexity
        if a not in seen:  #O(1) operation in terms of time complexity
            result.append(a)
            seen.add(a)
    return result


from collections import OrderedDict
def distinct(seq):
    return list(OrderedDict.fromkeys(seq))

def distinct(seq):
    return list(dict.fromkeys(seq))

def distinct(seq):
    nl = []
    [nl.append(i) for i in seq if i not in nl]
    return nl

def distinct(seq):
    result = []
    for item in seq:
        if item not in result:
            result.append(item)

    return result

distinct = lambda s: [e for i,e in enumerate(s) if e not in s[:i]]

def distinct(seq):
    result = []
    uniques = {i:True for i in set(seq)}
    for object in seq:
        if uniques[object]:
            result.append(object)
            uniques[object] = False
    return result

def distinct(seq):
    res = []
    for x in seq:
        if res.count(x) == 0:
            res.append(x)
    return res

def distinct(seq):
    s = set(seq)
    return [s.remove(n) or n for n in seq if n in s]

from collections import OrderedDict

def distinct(numbers):
    return list(OrderedDict.fromkeys(numbers).keys())

def distinct(seq):
    new_seq = []
    [new_seq.append(seq[i]) for i in range(len(seq)) if seq[i] not in new_seq]
    return new_seq

from typing import List

def distinct(seq: List[int]) -> List[int]:
    """ Remove duplicates from an array of numbers and return it as a result. """
    return list(dict.fromkeys(seq))

def distinct(seq):
    return [x for i,x in enumerate(seq) if i == seq.index(x)]

def distinct(seq):
    newSeq, tmp = [], None
    
    for i in seq:
        if i != tmp and i not in newSeq:
            newSeq.append(i)
            tmp = i
            
    return newSeq

def distinct(seq):
    i = []
    for x in seq:
        if x not in i:
            i.append(x)
    return i

# from more_itertools import unique_everseen as distinct

from itertools import filterfalse

def unique_everseen(iterable):
    seen = set()
    seen_add = seen.add
    for element in filterfalse(seen.__contains__, iterable):
        seen_add(element)
        yield element
        
distinct = lambda arr: list(unique_everseen(arr))   
        


distinct = lambda seq: [ seq[i] for i in range(len(seq)) if seq[i] not in seq[:i] + seq[i+1:] or i == seq.index(seq[i]) ]

def distinct(seq):
    seen = set()
    return [x for x in seq if not (x in seen or seen.add(x))]

distinct=lambda s:[v for i,v in enumerate(s) if v not in s[:i]]

def distinct(seq):
    v=[]
    for a in seq:
        if a not in v:
            v.append(a)
    return v

def distinct(num):
    uni = []
    for n in num:
        if n not in uni:
            uni.append(n)
    return uni

def distinct(seq):
    out=[]
    for x in seq :
        if not x in out : out.append(x)
    return out

def distinct(seq) :
    unique = []
    for x in seq :
        if x not in unique :
            unique.append(x)
    return unique

def distinct(seq):
    #return list(set(seq))
    
    seq2 = []
    for i in seq:
        if i not in seq2:
            seq2.append(i)
    return seq2

def distinct(seq):
    mylist = []
    for i in seq:
        if i not in mylist:
            mylist.append(i)
    return mylist

def distinct(seq):
    res=list()
    for item in seq:
        if item not in res:
            res.append(item)
    return res


def distinct(seq):
    res = []
    for num in seq:
        if num not in res:
            res.append(num) 
    print(res)
    return res


def distinct(seq):
    seq1 = list()
    for i in seq:
        if i not in seq1:
            seq1.append(i)
    return seq1

def distinct(seq):
    return sorted(set(seq), key=lambda d: seq.index(d))

def distinct(seq):
    arr = [seq[0]]
    a = seq[0]
    for x in range(1, len(seq)):
        if not seq[x] in arr:
            arr.append(seq[x])
    return arr

def distinct(seq):
    oplst = []
    
    for s in seq:
        if s not in oplst:
            oplst.append(s)
    
    return oplst

def distinct(seq):
    lst = []
    for el in seq:
        if el not in lst:
            lst.append(el)
    
    return lst

def distinct(seq):
    unique_lst = []
    for num in seq:
        if num not in unique_lst:
            unique_lst.append(num)
    return unique_lst

def distinct(seq):
    lst = list(dict.fromkeys(seq))
    return lst

def distinct(seq):
    a = set()
    return [x for x in seq if x not in a and not a.add(x)]

def distinct(seq):
    sq = []
    for i in seq:
        if i not in sq:
            sq.append(i)
        else:
            pass
    return sq

def distinct(seq):
    uniq_seq =[]
    for el in seq:
        if el not in uniq_seq:
            uniq_seq.append(el)
    return uniq_seq


def distinct(seq):
    n = []
    for x in seq:
        if x not in n:
            n.append(x)
    return n

def distinct(seq):
    k = list(dict.fromkeys(seq))
    return k

distinct = lambda s:[n for i, n in enumerate(s) if not (s.count(n)>1 and s.index(n)<i)]

def distinct(seq):
    unique = []
    for c in seq:
        if c not in unique:
            unique.append(c)
            
    return unique

def distinct(seq):
    check = []
    for item in seq:
        if item not in check:
            check.append(item)
    return check

def distinct(seq):
    # create new array
    array = []
    for x in seq:
        if x not in array:
            array.append(x)
    return array

def distinct(seq):
    d = {}
    for s in seq:
        d[s] = 1
    return list(d.keys())

def distinct(seq):
    found = set()
    result = []
    for i in seq:
        if i in found:
            continue
        result.append(i)
        found.add(i)
    return result

def distinct(seq):
    return list({i : i for i in seq}.keys())


def distinct(seq):
    r = []
    s = set()
    for n in seq:
        if n not in s:
            s.add(n)
            r.append(n)
    return r

def distinct(seq):
    unique = []
    for s in seq:
        if s not in unique:
            unique.append(s)
            
    return unique

def distinct(seq):
    result_mas = []
    for i in seq:
        if i not in result_mas:
            result_mas.append(i)
    return result_mas

def distinct(seq):
    l = []
    for elem in seq:
        if elem not in l:
            l.append(elem)
    return l

def distinct(seq):
    done = set()
    return [x for x in seq if not (x in done or done.add(x))]

def distinct(seq):
    k = []
    for i in seq:
        if i not in k:
            k += [i]
    return k


def distinct(seq):
    new_list = []
    [new_list.append(item) for item in seq if item not in new_list]
    return new_list

def distinct(seq):
    a = []
    for el in seq:
        if el not in a:
            a.append(el)
    return a

def distinct(seq):
    test_list = list( dict.fromkeys(seq) ) 
    return test_list

from itertools import groupby
def distinct(seq):
    seq_new = []
    for i in seq:
        if i not in seq_new:
            seq_new.append(i)
    return seq_new
    


def distinct(seq):
    answer = []
    for a in seq:
        if answer.count(a)==0:
            answer.append(a)
    return answer

def distinct(seq):
    result = []
    for item in seq:
        if item not in result:
            result.append(item)

    return result

print(distinct([1,1,2]))

def distinct(seq):
    s = set(seq)
    res = []
    for e in seq:
        if e in s:
            res.append(e)
            s.remove(e)
    return res

def distinct(seq):
    sum = []
    for i in seq:
        if i not in sum:
            sum.append(i)
    return sum

def distinct(arr):
    newA = []
    for el in arr:
        if not el in newA:
            newA.append(el)
    return newA

def distinct(seq):
    seq = list(dict.fromkeys(seq))
    return seq

def distinct(sequence):
    seen = set()
    return [x for x in sequence if not (x in seen or seen.add(x))]


def distinct(seq):
    clean = []
    for i in seq:
        if i not in clean:
            clean.append(i)
    return clean

def distinct(seq):
    
    available = []
    ret = []
    for item in seq:
        if item in available:
            continue
        available.append(item)
        ret.append(item)
        
    return ret

def distinct(seq):
    l=set(seq)
    g=[]
    for i in seq:
        if i in l:
            g.append(i)
            l.remove(i)
    return g

def distinct(seq):
    list = []
    for i in seq:
        if not i in list:
            list.append(i)
        else:
            pass
    return list

def distinct(seq):
    liste = []
    for a in seq:
        if not a in liste:
            liste.append(a)
    return liste

def distinct(seq):
    return [i[1] for i in enumerate(seq) if i[1] not in seq[:i[0]]]

def distinct(seq):
    uniqueList = []
    
    # Iterate over the original list and for each element
    # add it to uniqueList, if its not already there.
    for elem in seq:
        if elem not in uniqueList:
            uniqueList.append(elem)
    
    # Return the list of unique elements        
    return uniqueList
 


def distinct(seq):
    
# =============================================================================
#     This function removes duplicates from an array of numbers and returns it 
#     as a result.
#     The order of the returned sequence is the same as found in the given list
#     
#     Example:
#         distinct([1, 1, 2]) ==> [1, 2]
# =============================================================================
    
    result = []
    
    for num in seq:
        if num not in result:
            result.append(num)
    
    return result

def distinct(seq):
    lista_filtrada = []
    for i in seq:
        if i not in lista_filtrada:
            lista_filtrada.append(i)
    return(lista_filtrada)

def distinct(seq):
    l=[]
    for i in seq:
        if i not in l:
            l.append(i)
        else:
            pass
    return l

def distinct(seq):
    newlist = []
    for eachnumber in seq:
        if eachnumber in newlist:
            continue
        else:
            newlist.append(eachnumber)
    return newlist

def distinct(seq):
    ls=[]
    for i in seq:
        if i in ls:
            continue
        ls.append(i)
    return ls

def distinct(seq):
    result = []
    for num in seq:
        if result.count(num) < 1:
            result.append(num)
    return result

def distinct(seq):
    r = []
    for i in seq:
        if not i in r:
            r.append(i)
    return r

def distinct(seq):
    """return list of distnct values maintaining list order"""
    return [ seq[i] for i in range(len(seq)) if seq[i] not in seq[:i] ]


def distinct(seq):
    new_seq = []
    for c in seq:
        if c not in new_seq:
            new_seq.append(c)
    return new_seq

def distinct(seq):
    new_list = []
    for elem in seq:
        if elem not in new_list:
            new_list.append(elem)
    return new_list

def distinct(seq):
    new_lst = []
    for i in seq:
        if i not in new_lst:
            new_lst.append(i)
            
    return new_lst

def distinct(seq):
    numbers = []
    
    for elem in seq:
        if elem not in numbers:
            numbers.append(elem)
    
    return numbers

def distinct(seq):

    dct= {}
    lst = list()
    
    for i in seq:
      if i not in dct:
        dct[i] = 1
      else:
        dct[i] = dct[i] + 1

    for j in dct.keys():
      lst.append(j)
    return lst 

def distinct(seq):
    arr = []
    used = set()
    
    for n in seq:
        if n not in used:
          arr.append(n)
          used.add(n)
          
    return arr

def distinct(seq):
    salida = []

    for elmnt in seq:
        if elmnt not in salida:
            salida.append(elmnt)
            
    return salida

def distinct(seq):
    result=[]
    seen=[]
    for i in seq:
        if i not in seen:
            result.append(i)
            seen.append(i)
    return result        

def distinct(seq):
    l1 = []
    for x in seq:
        if x not in l1:
            l1.append(x)
    return l1

def distinct(seq):
    bob=[]
    i=0
    while i<len(seq):
        if seq[i] not in bob: bob.append(seq[i])
        i+=1

    return bob

from collections import Counter

def distinct(numbers):
  number_counts = Counter(numbers)

  return list(number_counts)


from collections import Counter

def distinct(numbers):
  number_counts = Counter(numbers)

  return list(number_counts.keys())


def distinct(seq):
    item = []
    for i in seq:
        if i not in item:
            item.append(i)
    return item            

from collections import Counter
def distinct(seq) :
    listt = list()
    seq = Counter(seq)
    for i in list(seq.items()) :
        listt.append(i[0])

    return listt
    


    


def distinct(a):
    b = {}
    return [b.setdefault(d, d) for d in a if d not in b]


def distinct(seq):
  sol=[]
  for num in seq:
    if num not in sol:
      sol.append(num)
  return sol



def distinct(seq):
    import collections
    return [i for i in dict(collections.Counter(seq))]

def distinct(seq):
    test = set()
    unique = []
    for x in seq:
        if x not in test:
            unique.append(x)
            test.add(x)
    return unique


def distinct(seq):
    list = []
    for value in seq:
        if value not in list:
            list.append(value)      
    return list


def distinct(seq):
    c=[]
    for i in seq:
        if i not in c:
            c.append(i)
    return c