470,849 Members | 1,590 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

Zip with sequences of diffrent length

Hi all,

I want to make tuples of the elements of a list like this.

l = [1, 2, 3]

Wanted tuples:

(1, 2)
(2, 3)
(3, None)

I can get the first two tuples using zip(l, l[1:]). How do I get the
last one?

Many thanks in advance,
Nicky
Jul 18 '05 #1
2 1260
Nickolay Kolev wrote:
I want to make tuples of the elements of a list like this.

l = [1, 2, 3]

Wanted tuples:

(1, 2)
(2, 3)
(3, None)

I can get the first two tuples using zip(l, l[1:]). How do I get the
last one?

l = [1, 2, 3]
zip(l, l[1:]+[None])

[(1, 2), (2, 3), (3, None)]

Jul 18 '05 #2
Use map( None, l, l[1:] )

HTH,
Mike

Nickolay Kolev wrote:
....
Wanted tuples:

(1, 2)
(2, 3)
(3, None)

I can get the first two tuples using zip(l, l[1:]). How do I get the
last one?


....
_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Thomas Philips | last post: by
5 posts views Thread by Minho Chae | last post: by
4 posts views Thread by temp | last post: by
13 posts views Thread by Rick Brandt | last post: by
2 posts views Thread by Roggey | last post: by
3 posts views Thread by Philip Wagenaar | last post: by
4 posts views Thread by Anthra Norell | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.