[Tutor] Select distinct item form list
Bob Gailer
ramrom@earthling.net
Mon Feb 24 09:35:02 2003
--=======549E270A=======
Content-Type: text/plain; x-avg-checked=avg-ok-267B1AE6; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit
At 08:38 AM 2/24/2003 +0100, janos.juhasz@VELUX.com wrote:
>Can someone show me a simple list comprehension to do the same thing as
>"Select distinct item form list" does in SQL
>
>So i have a list
> >>> l = (1,2,3,4,5,5,6,7,7,7,2)
>but i would have just
>l=(1,2,3,4,5,6,7)
Consider, also:
>>> def r(a,b):
... if a != b:l2.append(b)
... return b
...
>>> l = [1,2,3,4,5,5,6,7,7,7,2]
>>> l.sort()
>>> l2=[l[0]]
>>> reduce(r,l)
5
>>> l2
[1, 2, 3, 4, 5, 6, 7]
Bob Gailer
mailto:ramrom@earthling.net
303 442 2625
--=======549E270A=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-267B1AE6
Content-Disposition: inline
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.454 / Virus Database: 253 - Release Date: 2/10/2003
--=======549E270A=======--