473,322 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 1313
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomas Philips | last post by:
I have been playing around with reading strings with embedded escape sequences from files both using readline() and codecs.open() and have a question.I create a file "test.txt" with exactly one...
5
by: Minho Chae | last post by:
Hello, python lovers!! I'm trying to create combinations of sequences. For example, if the sequence is 'acgt' and the length is 8, then I would like to have 4^8 results such as 'aaaaaaaa',...
4
by: temp | last post by:
Hi All, I wonder could someone help me with this? What I want to do is search through a list of letters and look for adjacent groups of letters that form sequences, not in the usual way of...
13
by: Rick Brandt | last post by:
If you examine the complete XML below you will see an element "Notes" consisting of... <Notes>test replace test&amp;replace</Notes> As you can see I have properly (I think) escaped the ampersand...
2
by: Roggey | last post by:
Hello I'm using System.Windows.Forms.Label and I want to add some text, where one or more words are bold or italic. I tried it with html tags but does not work. Somewhere i did read it should...
6
by: Ryan | last post by:
Hi, I am confused with how NetworkStream works. My application needs to handle heavy requests sent through TCP socket connection. I use NetworkStream.Read method to get the stream...
3
by: Philip Wagenaar | last post by:
Framework 1.1 I want to start AcrobatReader to print a printjob under a specific username (so that the owner of the printjob is not the username of the application that the .net application runs...
1
by: ABCL | last post by:
Hi All, I am working on the situation where 2 different Process/Application(.net) tries to open file at the same time....Or one process is updating the file and another process tries to access...
4
by: Anthra Norell | last post by:
Hi, I keep working around a little problem with unpacking in cases in which I don't know how many elements I get. Consider this: def tabulate_lists (*arbitray_number_of_lists): table = zip...
1
by: krikaran adel | last post by:
Hi, First of all I found your tips very usfull, of course these tips becuas of all years working in access. really greet site. my Quation: is this away to change fonts in reports so the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.