[Tutor] Select distinct item form list

Michael Janssen Janssen@rz.uni-frankfurt.de
Mon Feb 24 04:47:01 2003


On Mon, 24 Feb 2003 janos.juhasz@VELUX.com wrote:

> Dear All,
>
> 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 =3D (1,2,3,4,5,5,6,7,7,7,2)
> but i would have just
> l=3D(1,2,3,4,5,6,7)

Okey first try:

>>> l
(1, 2, 3, 4, 5, 5, 6, 7, 7, 7, 2)
>>> def uniqs(inp, was_there=3D[]):
=2E..   if not inp in was_there:
=2E..     was_there.append(inp)
=2E..     return 1  # sending "True" to filter
=2E..
>>> filter(si, l)
(1, 2, 3, 4, 5, 6, 7)

for filter best look at Python Tutorial Section 5.1.3

>
> I know i have seen this somewhere, but i cannot find it :(
>
> Please CC me.
> Best regards,
> -----------------------
> Juh=E1sz J=E1nos
> IT department
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>