Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Create a <a href="http://docs.python.org/2/tutorial/classes.html#generators" rel="nofollow noreferrer">generator function</a> that yields smaller and smaller <a href="https://stackoverflow.com/questions/509211/pythons-slice-notation">slices</a> of the given string.</p> <pre><code>def shrink(s): for i in range(len(s)): yield s[i:] </code></pre> <p>Create a function that splits a string into a list of five character segments.</p> <pre><code>def split_into_five_character_segments(s): ret = [] while len(s) &gt; 5: ret.append(s[:5]) s = s[5:] ret.append(s) return ret </code></pre> <p>Combine the two in a <a href="http://docs.python.org/2/tutorial/datastructures.html#list-comprehensions" rel="nofollow noreferrer">list comprehension</a> to generate your fragment library.</p> <pre><code>sequence = "MSSPPPARSGFYRQEVTKTAWEVRAVYRDLQ" fragments = [split_into_five_character_segments(s) for s in shrink(sequence)] </code></pre> <p><a href="http://docs.python.org/2/library/functions.html#enumerate" rel="nofollow noreferrer">Enumerate</a> through each fragment. Use <a href="http://docs.python.org/2/library/stdtypes.html?highlight=join#str.join" rel="nofollow noreferrer"><code>join</code></a> to combine the pieces of the fragment into a single space-separated string.</p> <pre><code>for idx, fragment in enumerate(fragments): fragment_number = idx + 1 indent = " " * idx print indent + str(fragment_number) print indent + " ".join(fragment) </code></pre> <p>Result:</p> <pre><code>1 MSSPP PARSG FYRQE VTKTA WEVRA VYRDL Q 2 SSPPP ARSGF YRQEV TKTAW EVRAV YRDLQ 3 SPPPA RSGFY RQEVT KTAWE VRAVY RDLQ 4 PPPAR SGFYR QEVTK TAWEV RAVYR DLQ 5 PPARS GFYRQ EVTKT AWEVR AVYRD LQ 6 PARSG FYRQE VTKTA WEVRA VYRDL Q 7 ARSGF YRQEV TKTAW EVRAV YRDLQ 8 RSGFY RQEVT KTAWE VRAVY RDLQ 9 SGFYR QEVTK TAWEV RAVYR DLQ 10 GFYRQ EVTKT AWEVR AVYRD LQ 11 FYRQE VTKTA WEVRA VYRDL Q 12 YRQEV TKTAW EVRAV YRDLQ 13 RQEVT KTAWE VRAVY RDLQ 14 QEVTK TAWEV RAVYR DLQ 15 EVTKT AWEVR AVYRD LQ 16 VTKTA WEVRA VYRDL Q 17 TKTAW EVRAV YRDLQ 18 KTAWE VRAVY RDLQ 19 TAWEV RAVYR DLQ 20 AWEVR AVYRD LQ 21 WEVRA VYRDL Q 22 EVRAV YRDLQ 23 VRAVY RDLQ 24 RAVYR DLQ 25 AVYRD LQ 26 VYRDL Q 27 YRDLQ 28 RDLQ 29 DLQ 30 LQ 31 Q </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload