Questions about tuple?

Mindy csshi99 at yahoo.com
Fri Nov 8 22:51:58 EST 2002


> > >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?
> 
> Well, you can call it homework as it's a tiny thing
> of
> my project. In ML, it's easy to do this using #, and
> I
> just wonder how to do this in Python. I'm just a
> newbie in Python and don't know the many things it
> can
> do. I can do this in a clumsy way but I think I
> might
> don't know some functions in Python which can do
> this
> in a simple but neat way.
> 
> Thanks for any hints.
> 
> 
> =====
> Cheers
> -Mindy
> 
> __________________________________________________
> Do you Yahoo!?
> U2 on LAUNCH - Exclusive greatest hits videos
> http://launch.yahoo.com/u2
> 


=====
Cheers
-Mindy

__________________________________________________
Do you Yahoo!?
U2 on LAUNCH - Exclusive greatest hits videos
http://launch.yahoo.com/u2




More information about the Python-list mailing list