[Tutor] String slicing from tuple list

Luis N tegmine at gmail.com
Thu Jul 21 22:05:10 CEST 2005


On 21 Jul 2005 20:39:36 +0100, cgw501 at york.ac.uk <cgw501 at york.ac.uk> wrote:
> 
> Hi,
> 
> I have a list of tuples like this:
> 
> [(1423, 2637),(6457, 8345),(9086, 10100),(12304, 15666)]
> 
> Each tuple references coordinates of a big long string and they are in the
> 'right' order, i.e. earliest coordinate first within each tuple, and
> eearliest tuple first in the list. What I want to do is use this list of
> coordinates to retrieve the parts of the string *between* each tuple. So 
> in
> my example I would want the slices [2367:6457], [8345:9086] and
> [10100:12304]. Hope this is clear.
> 
> I'm coming up short of ideas of how to achieve this. I guess a for loop,
> but I'm not sure how I can index *the next item* in the list, if that 
> makes
> sense, or perhaps there is another way.
> 
> Any help, as ever, appreciated.
> 
> Chris
> 
> Not sure if I follow you, seems like computational biology or something to 
> me, but my quick (and dirty) solution:
> 

l = [(1423, 2637),(6457, 8345),(9086, 10100),(12304, 15666)]

for x in range(len(l)-1):
> l[x][1], l[x+1][0]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050721/cce1bb4a/attachment.htm


More information about the Tutor mailing list