Questions about tuple?

Bengt Richter bokr at oz.net
Fri Nov 8 20:58:33 EST 2002


On Fri, 8 Nov 2002 16:27:11 -0800 (PST), Mindy <csshi99 at yahoo.com> wrote:

>Hey, given a tuple t(a,b), is there any function in
>Python that I can get a, b individually from t?
>Actually, I have a list whose element is tuples. Say:
>
>tuple_list = [(1,'a'),(3,'b'),(2,'l'),(8,'p')]
>
>Then I want to get two lists from this tuple_list. The
>first list contains the first elements in the tuple of
>the tuple_list. 
>
>first_list = [1,3,2,8]
>
>And the second list contains all the second elements,
>also maintaining the original order as in tuple_list.
>
>second_list = ['a','b','l','p']
>
>So how to get this easily? Thanks!
>
This sounds like homework. Is it?

Regards,
Bengt Richter



More information about the Python-list mailing list