[Tutor] putting a short list of integers into a (specific)
compact form
Gabor Borgulya
bvg.pythontutor at freemail.hu
Sun Oct 12 06:31:57 EDT 2003
2003-10-12, v keltezéssel kevin parks ezt írta:
> 1. Initially, all duplicate elements should be eliminated and the
> elements should
> be written so that they are ascending in order
>>> l=[1,8,5,3,7,8,2,11,1,2,0,5] # a list with duplicate elements
>>> wod=[] # this will be the new list without duplicates
>>> for i in l:
... if i not in wod: # we append only if it is not already there
... wod.append(i)
...
>>> wod
[1, 8, 5, 3, 7, 2, 11, 0]
>>> wod.sort() # sort in place
>>> wod
[0, 1, 2, 3, 5, 7, 8, 11]
I couldn't understand the rest of your question.
Hope this helps.
Gábor
More information about the Tutor
mailing list