[Tutor] selecting specific items from a list

Praveen Pathiyil ppathiyi@cisco.com
Tue, 8 May 2001 18:14:04 +0530


I feel that the following should do the job for you...

list1 = [(3,3),(2,0),(5,5), (1,1), (4,5), ('a','a'), ('a','e'), ('b','b'),
('c','d')]
eq_list = []

for (x,y) in list1:
    if x==y:
        eq_list.append(x,y)

Regards,
Praveen.


----- Original Message -----
From: "Julieta Rangel" <julieta_rangel@hotmail.com>
To: <tutor@python.org>
Sent: Tuesday, May 08, 2001 6:03 PM
Subject: [Tutor] selecting specific items from a list


> Let's say I have the following list:
>
> [(3,3),(2,0),(5,5), (1,1), (4,5), (a,a), (a,e), (b,b), (c,d)]
>
> How can I tell the computer to return to me only those items in the list
for
> which x==y.  That is, [(3,3), (5,5), (1,1), (a,a), (b,b)].
>
> It's a dumb question, but somebody's got to ask it :)
>
> Julieta
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>