C Smith wrote:

On Tuesday, Mar 22, 2005, at 05:01 America/Chicago, [EMAIL PROTECTED] wrote:


I met a similar question.
what if one has L = [[1,2],[3,4]], K = [100, 200]
How to 'zip' a List like [[1,2,100], [3,4,200]]?

I would do something like:

###
for i in range(len(L)):
  L[i].append(K[i])
###

Oh, the light goes on :-) Thanks C Smith!

Here is another way:
 >>> L = [[1,2],[3,4]]
 >>> K = [100, 200]
 >>> [ x+[y] for x, y in zip(L, K) ]
[[1, 2, 100], [3, 4, 200]]

Note C Smith's approach modifies L to include the items in K; my approach makes 
a new list.

Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to