Series18. An integer N and a set of N integers, ordered in ascending order are given. This set may contain the same elements. Output in the same order all the different elements of this set.

Solution in Python 3:

import random

N = random.randrange(1,20)
print("N = ",N)

l = [0]
for i in range(1,N):
x = random.randrange(1,6)
if x == 1:
l.append(i)
while x == 2 or x == 3:
l.append(i)
x = random.randrange(1,6)

print(l)

l2 = []
l2.append(l[0])
N = len(l)
for j in range(1,N):
if l[j] > l[j-1]:
l2.append(l[j])
print(l2)
print(list(set(l)))