[Python Glasgow] consecuetive members of a list
Marc Cameron
marccameron3d at gmail.com
Wed Apr 30 12:09:54 CEST 2014
Hi Hedieh,
myList = [1,7,19,1110]
newList = []
for x in range(0, len(myList)-1):
newStr = "(,)"
newList.append("("+str(myList[x])+","+str(myList[x+1])+")")
Not sure if it meets your requirements, although this should work for all
intents and purposes. I am still relatively new to python so there may be a
better way.
Output = ['(1,7)', '(7,19)', '(19,1110)']
Cheers,
Marc C
------------------
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.
On 30 April 2014 10:53, Hedieh Ebrahimi <hedieh.ebrahimi at amphos21.com>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 ?
>
> Thanks in advance.
>
> _______________________________________________
> Glasgow mailing list
> Glasgow at python.org
> https://mail.python.org/mailman/listinfo/glasgow
>
>
--
Marc Cameron
*Contract Technical Artist and AR Generalist*
t: *+447595491710*
e: marccameron3D at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/glasgow/attachments/20140430/1396e32a/attachment.html>
More information about the Glasgow
mailing list