By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

Zip with sequences of diffrent length

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.