[Python Glasgow] consecuetive members of a list

Hedieh Ebrahimi hedieh.ebrahimi at amphos21.com
Wed Apr 30 12:19:39 CEST 2014


Thanks Marc

Ill try that out, but hopefully I just found this  that works for me

def createRangeOfIndices(self,myArray,d):
        ranges=[]
        for index in range(len(myArray)):
            if index < len(myArray)-1:
                myTuple=(myArray[index],myArray[index+1])
                ranges.append(myTuple)
        return ranges


Thanks :)


On 30 April 2014 12:09, Marc Cameron <marccameron3d at gmail.com> wrote:

> 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/e873ebc1/attachment.html>


More information about the Glasgow mailing list