Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For large string, iterator is recommended for speed and low memory footprint.</p> <pre><code>import re, itertools # Original text text = "When in the course of human Events, it becomes necessary for one People to dissolve the Political Bands which have connected them with another, and to assume among the Powers of the Earth, the separate and equal Station to which the Laws of Nature and of Nature?s God entitle them, a decent Respect to the Opinions of Mankind requires that they should declare the causes which impel them to the Separation." n = 10 # An iterator which will extract words one by one from text when needed words = itertools.imap(lambda m:m.group(), re.finditer(r'\w+', text)) # The final iterator that combines words into n-length groups word_groups = itertools.izip_longest(*(words,)*n) for g in word_groups: print g </code></pre> <p>will get the following result:</p> <pre><code>('When', 'in', 'the', 'course', 'of', 'human', 'Events', 'it', 'becomes', 'necessary') ('for', 'one', 'People', 'to', 'dissolve', 'the', 'Political', 'Bands', 'which', 'have') ('connected', 'them', 'with', 'another', 'and', 'to', 'assume', 'among', 'the', 'Powers') ('of', 'the', 'Earth', 'the', 'separate', 'and', 'equal', 'Station', 'to', 'which') ('the', 'Laws', 'of', 'Nature', 'and', 'of', 'Nature', 's', 'God', 'entitle') ('them', 'a', 'decent', 'Respect', 'to', 'the', 'Opinions', 'of', 'Mankind', 'requires') ('that', 'they', 'should', 'declare', 'the', 'causes', 'which', 'impel', 'them', 'to') ('the', 'Separation', None, None, None, None, None, None, None, None) </code></pre>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. 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