You are on the right track, but you are using sorted
, sorted() returns a new sorted list, leaving the original list unaffected
sort()
sorts the list in-place, mutating the list indices, and returns None
We cam use sorted on any itterable, list, dict, string, tupple.
Hence, use sorted(),
when you want a sorted object back and sort()
when u want to mutate the list.
As compare with sorted()
, sort()
is fast as it do not copy.
Read complete here : What is the difference between sorted(list)
vs list.sort()
?
SOLUTION :
N=int(raw_input())
A=raw_input()
a_list=A.split()
for i in xrange (len(a_list)):
a_list[i]=int(a_list[i])
s=list(set(a_list))
s.sort()
print(s)