[Python Glasgow] consecuetive members of a list

Kevin McDermott kevin.mcdermott at canonical.com
Wed Apr 30 12:42:31 CEST 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 30/04/14 10:53, Hedieh Ebrahimi wrote:
> 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 ?
>
>
This is so commonly done, that it's even documented in the Python
standard library...

https://docs.python.org/2/library/itertools.html see "pairwise"

HTH,

Kevin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlNg05cACgkQeXQZLS7Rd7JKogCeJq90QSwtDO+Xr5ab2jNSzQIC
SRYAoMAM7GHf2/S1aTJFj6MvtjIVlSXL
=HSzh
-----END PGP SIGNATURE-----



More information about the Glasgow mailing list