Grokbase Groups Python tutor May 2011
FAQ
Greetings Python List,

I have a motif sequence (a list of characters e.g. 'EAWLGHEYLHAMKGLLC')
whose index I would like to return.
The list contains 20 strings, each of which is close to 1000 characters long
making it far too cumbersome to display an example.
I would like to know if there is a way to return a pair of indices, one
index where my sequence begins (at 'E' in the above case) and
one index where my sequence ends (at 'C' in the above case). In short, if
'EAWLGHEYLHAMKGLLC' spans 17 characters is it possible
to get something like 100 117, assuming it begins at 100th position and goes
up until 117th character of my string. My loop goes as
follows:

for item in finalmotifs:
for line in my_list:
if item in line:
print line.index(item)

But this only returns a single number (e.g 119), which is the index at which
my sequence begins.

Is it possible to get a pair of indices that indicate beginning and end of
substring?

Many thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110518/fd766e91/attachment.html>

Search Discussions

  • Alan Gauld at May 18, 2011 at 12:27 am
    "Spyros Charonis" <s.charonis at gmail.com> wrote
    for item in finalmotifs:
    for line in my_list:
    if item in line:
    print line.index(item)

    But this only returns a single number (e.g 119), which is the index
    at which
    my sequence begins.

    Is it possible to get a pair of indices that indicate beginning and
    end of
    substring?

    print line.index(item)+len(item)

    Presumably since its matching item the end index will be len(item)
    characters later? Or am I missing something?

    Alan G.
  • Spawgi at May 18, 2011 at 8:03 am
    Agreed that your original sequences are 1000 char long. But it helps to
    understand the problem better if you can give examples with smaller strings.
    Please can you post smaller examples? This will also help you test your code
    on your own inputs.
    On Wed, May 18, 2011 at 5:40 AM, Spyros Charonis wrote:

    Greetings Python List,

    I have a motif sequence (a list of characters e.g. 'EAWLGHEYLHAMKGLLC')
    whose index I would like to return.
    The list contains 20 strings, each of which is close to 1000 characters
    long making it far too cumbersome to display an example.
    I would like to know if there is a way to return a pair of indices, one
    index where my sequence begins (at 'E' in the above case) and
    one index where my sequence ends (at 'C' in the above case). In short, if
    'EAWLGHEYLHAMKGLLC' spans 17 characters is it possible
    to get something like 100 117, assuming it begins at 100th position and
    goes up until 117th character of my string. My loop goes as
    follows:

    for item in finalmotifs:
    for line in my_list:
    if item in line:
    print line.index(item)

    But this only returns a single number (e.g 119), which is the index at
    which my sequence begins.

    Is it possible to get a pair of indices that indicate beginning and end of
    substring?

    Many thanks



    _______________________________________________
    Tutor maillist - Tutor at python.org
    To unsubscribe or change subscription options:
    http://mail.python.org/mailman/listinfo/tutor

    --
    http://spawgi.wordpress.com
    We can do it and do it better.
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/tutor/attachments/20110518/50b6aa51/attachment.html>

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouptutor @
categoriespython
postedMay 18, '11 at 12:10a
activeMay 18, '11 at 8:03a
posts3
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase