How about this? Not only does it count each element, but you can also get a
sorted set without using set!
a = [24,24,24,16,16,15,15]
b = {}
for i in a:
try: b[i] += 1
except KeyError: b[i] = 1
print b
li = b.keys()
print li
li.sort()
print li
li.reverse()
print li
has output
{24: 3, 16
On Tue, 23 Aug 2005, Kent Johnson wrote:
> Actually the reverse parameter is new in 2.4 too, you have to do that in
> a separate step also:
Doh!
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
I've done:
undup = []
for i in list:
if i not in undup:
undup.append(i)
Which is simple an not very pythonic, but does the trick.
Hugo
Jonas Melian wrote:
> I get a list of repeated numbers [24, 24, 24, 16, 16, 15, 15 ]
> Is possible get it without repeated numbers, without usi
Terry Carroll wrote:
> Sorry, I missed you were on 2.3.x, and I think sorted() is new with 2.4.
> You'd instead have to do the sort in a separate step:
>
>
l=[24, 24, 15, 16, 16, 15, 24]
l=list(set(l))
l.sort(reverse=True)
l
>
> [24, 16, 15]
Actually the reverse parameter is n
On Tue, 23 Aug 2005, Terry Carroll wrote to Jonas:
> I don't know if you're in a position to rely on the sortedness of the
> input data, but even if not, this works:
>
> >>> l=[24, 24, 15, 16, 16, 15, 24]
> >>> l=sorted(list(set(l)), reverse=True)
> >>> l
> [24, 16, 15]
Sorry, I missed you were
On Tue, 23 Aug 2005, Jonas Melian wrote:
> I get a list of repeated numbers [24, 24, 24, 16, 16, 15, 15 ]
> Is possible get it without repeated numbers, without using set()?
>
> If I use set, then the list is unsorted and i cann't sorting it.
Converting it to a set will eliminate dupes, and con
Jonas Melian wrote:
> I get a list of repeated numbers [24, 24, 24, 16, 16, 15, 15 ]
> Is possible get it without repeated numbers, without using set()?
>
> If I use set, then the list is unsorted and i cann't sorting it.
>
> A idea it would be create a generator that will return elements one by