Re: how to separate a list into two lists?

2011-08-06 Thread bud
On Sun, 07 Aug 2011 01:07:00 +0800, smith jack wrote:

> if a list L is composed with tuple consists of two elements, that is L =
> [(a1, b1), (a2, b2) ... (an, bn)]
> 
> is there any simple way to divide this list into two separate lists ,
> such that L1 = [a1, a2... an]
> L2=[b1,b2 ... bn]
> 
> i do not want to use loop, any methods to make this done?


(x,y) = [ [z[i] for z in L] for i in range(len(L[0]))]

x
: ['a1', 'a2', 'an']

y
: ['b1', 'b2', 'bn']


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to separate a list into two lists?

2011-08-06 Thread bud
On Sat, 06 Aug 2011 10:24:10 -0700, Emile van Sebille wrote:

> On 8/6/2011 10:07 AM smith jack said...
>> if a list L is composed with tuple consists of two elements, that is L
>> = [(a1, b1), (a2, b2) ... (an, bn)]
>>
>> is there any simple way to divide this list into two separate lists ,
>> such that L1 = [a1, a2... an]
>> L2=[b1,b2 ... bn]
>>
>>
>  >>> L = [('a1', 'b1'), ('a2', 'b2'),('an', 'bn')] zip(*L)
> [('a1', 'a2', 'an'), ('b1', 'b2', 'bn')]
> 

Nice. :)  I forgot about zip, still learning Python myself. 

I'll have to check up on the *L - is that a reference?
I know in Perl, you can assign the lhs to a list,
below works because there are exactly 2 items on the rhs.
Does Python have a catchall, or an ignore the rest?
Example, if L was a tuple that had 3 or more items, 
the below lhs would fail.  Is this possible in Python?


(X,Y) = zip(*L)


X
: ('a1', 'a2', 'an')

Y
: ('b1', 'b2', 'bn')



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python mascot proposal

2004-12-12 Thread Bud Rogers
richard wrote:

> Having said that, don't forget that Python's name has *nothing to do
> with snakes*. Please consider sticking to the original roots of the
> language's name: Monty Python's Flying Circus. IIRC, Guido has said a
> number of times that he's not fond of using a snake for logos.

Some time ago while cruising a Barnes & Noble I found a Python book I
hadn't seen before.  I don't remember the title at the moment, and I
don't have the book at hand, but the cover had a large python staring
down at a small frightened rodent.  When I went to check out, the
person at the counter was a kind of frumpy librarian type.  She looked
at the cover and made some snide remark about frightening small
children.   I thought for a moment about trying to explain to her that
the cover art was an inside joke on an inside joke.  When I realized
how far back I would have to go to unwind all the references, it just
didn't seem worth the trouble. 
-- 
http://mail.python.org/mailman/listinfo/python-list