I have the exercise below, but I cannot work it out, the code below is only the demonstration attempt, I have tried several others. Maybe someone can shed some light. If I use a nested for loop it only produces the cartesian product with all possible combinations. But obviously, I am missing something
Given a sequence of numbers with all of its elements in ascending order, returns the number of distinct elements in it.
Input:
1 1 2 3 3
Output:
3
and you cannot use set:
my_list=[1, 1, 2, 2, 2, 3, 5 ,6]
count=0
for x in my_list:
if x ==2:
count = count +1
print (count)