How to iterate the input over a particular size?

Aahz aahz at pythoncraft.com
Wed Jan 13 21:37:16 CET 2010


In article <46a5e979-7a87-49ee-ac7e-71d3a235d7f1 at e37g2000yqn.googlegroups.com>,
joy99  <subhakolkata1234 at gmail.com> wrote:
>
>input_string=raw_input("PRINT A STRING:")
>string_to_word=input_string.split()
>len_word_list=len(string_to_word)
>if len_word_list>9:
>             rest_words=string_to_word[9:]
>             len_rest_word=len(rest_words)
>             if len_rest_word>9:
>                      remaining_words=rest_words[9:]

input_string.split(None, 9) does something like what you want, but it
does require recopying the tail each iteration.  Overall, if you have
enough RAM and you don't need to preserve input_string after splitting,
your approach probably is the one I'd use.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair



More information about the Python-list mailing list