[Python Glasgow] Consecutive members of a list (Hedieh Ebrahimi)-Glasgow Digest, Vol 16, Issue 5

Nonso Ibenegbu jollynony at yahoo.com
Wed Apr 30 12:33:12 CEST 2014


Hi Hedieh,

See if you like this:

myList= [1, 7, 19, 1110]
 
newList = [(myList[x-1], myList[x]) for x in range(1, len(myList))]

Cheers.
Nonso




On 30 Apr 2014, at 11:00, glasgow-request at python.org wrote:

> Send Glasgow mailing list submissions to
> 	glasgow at python.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> 	https://mail.python.org/mailman/listinfo/glasgow
> or, via email, send a message with subject or body 'help' to
> 	glasgow-request at python.org
> 
> You can reach the person managing the list at
> 	glasgow-owner at python.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Glasgow digest..."
> 
> 
> Today's Topics:
> 
>   1. consecuetive members of a list (Hedieh Ebrahimi)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Wed, 30 Apr 2014 11:53:20 +0200
> From: Hedieh Ebrahimi <hedieh.ebrahimi at amphos21.com>
> To: Python Edinburgh <glasgow at python.org>
> Subject: [Python Glasgow] consecuetive members of a list
> Message-ID:
> 	<CA+ze5C7uKKRDSgd1zbx=99-Ce0wrz4soKL5yZLurBLpVdfAVAQ at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
> 
> Hi all,
> 
> Imagine I have a list like this:
> 
> myList= [1, 7, 19, 1110]
> 
> from this list I like to create a list of tuple of ranges like this.
> 
> [(1,7),(7,19),(19,1110)]
> 
> How can I do this in an efficient way ?
> 
> Thanks in advance.
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://mail.python.org/pipermail/glasgow/attachments/20140430/03b7aeae/attachment-0001.html>
> 
> ------------------------------
> 
> Subject: Digest Footer
> 
> _______________________________________________
> Glasgow mailing list
> Glasgow at python.org
> https://mail.python.org/mailman/listinfo/glasgow
> 
> 
> ------------------------------
> 
> End of Glasgow Digest, Vol 16, Issue 5
> **************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/glasgow/attachments/20140430/45a06e4a/attachment.html>


More information about the Glasgow mailing list