[Tutor] indexing a list

Spyros Charonis s.charonis at gmail.com
Thu Oct 18 14:01:59 CEST 2012


Hello pythoners,

I have a string that I want to read in fixed-length windows.

In [68]: SEQ
Out[68]:
'MKAAVLTLAVLFLTGSQARHFWQQDEPPQSPWDRVKDLATVYVDVLKDSGRDYVSQFEGSALGKQLNLKLLDNWDSVTSTFSKLREQLGPVTQEFWDNLEKETEGLRQEMSKDLEEVKAKVQPYLDDFQKKWQEEMELYRQKVEPLRAELQEGARQKLHELQEKLSPLGEEMRDRARAHVDALRTHLAPYSDELRQRLAARLEALKENGGARLAEYHAKATEHLSTLSEKAKPALEDLRQ'

I would like a function that reads the above string, 21 characters at a
time, and checks for certain conditions, i.e. whether characters co-occur
in other lists I have made. For example:

x = 21   # WINDOW LENGTH

In [70]: SEQ[0:x]
Out[70]: 'MKAAVLTLAVLFLTGSQARHF'

In [71]: SEQ[x:2*x]
Out[71]: 'WQQDEPPQSPWDRVKDLATVY'

In [72]: SEQ[2*x:3*x]
Out[72]: 'VDVLKDSGRDYVSQFEGSALG'

How could I write a function to automate this so that it does this from
SEQ[0] throughout the entire sequence, i.e. until len(SEQ)?

Many thanks for your time,
Spyros
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121018/5e5514cb/attachment.html>


More information about the Tutor mailing list