Re: How to iterate the input over a particular size?

2010-01-13 Thread Aahz
In article <46a5e979-7a87-49ee-ac7e-71d3a235d...@e37g2000yqn.googlegroups.com>, joy99 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

Re: How to iterate the input over a particular size?

2009-12-29 Thread John Posner
On Tue, 29 Dec 2009 01:35:41 -0500, Steven D'Aprano wrote: On Tue, 29 Dec 2009 00:49:50 -0500, John Posner wrote: On Sun, 27 Dec 2009 09:44:17 -0500, joy99 wrote: Dear Group, I am encountering a small question. Suppose, I write the following code, input_string=raw_input("PRINT A STRING:

Re: How to iterate the input over a particular size?

2009-12-29 Thread John Posner
On Tue, 29 Dec 2009 01:35:41 -0500, Steven D'Aprano wrote: On Tue, 29 Dec 2009 00:49:50 -0500, John Posner wrote: On Sun, 27 Dec 2009 09:44:17 -0500, joy99 wrote: Dear Group, I am encountering a small question. Suppose, I write the following code, input_string=raw_input("PRINT A STRING:

Re: How to iterate the input over a particular size?

2009-12-29 Thread John Posner
On Tue, 29 Dec 2009 01:35:41 -0500, Steven D'Aprano wrote: On Tue, 29 Dec 2009 00:49:50 -0500, John Posner wrote: On Sun, 27 Dec 2009 09:44:17 -0500, joy99 wrote: Dear Group, I am encountering a small question. Suppose, I write the following code, input_string=raw_input("PRINT A STRIN

Re: How to iterate the input over a particular size?

2009-12-28 Thread Steven D'Aprano
On Tue, 29 Dec 2009 00:49:50 -0500, John Posner wrote: > On Sun, 27 Dec 2009 09:44:17 -0500, joy99 > wrote: > >> Dear Group, >> >> I am encountering a small question. >> >> Suppose, I write the following code, >> >> input_string=raw_input("PRINT A STRING:") >> string_to_word=input_string.split()

Re: How to iterate the input over a particular size?

2009-12-28 Thread Ben Finney
"John Posner" writes: > I haven't found a generator version of the string function split(). Am > I missing something? To my knowledge there isn't one. Both Python 2 and Python 3 document ‘str.split’ as returning a list. -- \ “An idea isn't responsible for the people who believe in it.”

Re: How to iterate the input over a particular size?

2009-12-28 Thread John Posner
On Sun, 27 Dec 2009 09:44:17 -0500, joy99 wrote: Dear Group, I am encountering a small question. Suppose, I write the following code, 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=

Re: How to iterate the input over a particular size?

2009-12-28 Thread Peter Otten
Lie Ryan wrote: > On 12/28/2009 8:54 PM, Peter Otten wrote: >> Francesco Bochicchio wrote: >> One with lazy chunks: >> > from itertools import chain, islice > def chunks(items, n): >> items = iter(items) >> for first in items: >> yield chain((first,), isl

Re: How to iterate the input over a particular size?

2009-12-28 Thread joy99
On Dec 28, 5:28 pm, Vlastimil Brom wrote: > 2009/12/27 joy99 : > > > Dear Group, > > Answers were good. But I am looking for a smarter solution like: > > > for i[:2] in list: > > > > > etc. or by doing some looping over loop. > > Do not worry I'll work out the answer. > > > Wishing you a happ

Re: How to iterate the input over a particular size?

2009-12-28 Thread Lie Ryan
On 12/28/2009 8:54 PM, Peter Otten wrote: Francesco Bochicchio wrote: One with lazy chunks: from itertools import chain, islice def chunks(items, n): items = iter(items) for first in items: yield chain((first,), islice(items, n-1)) [list(chunk) for chun

Re: How to iterate the input over a particular size?

2009-12-28 Thread Vlastimil Brom
2009/12/27 joy99 : > Dear Group, > Answers were good. But I am looking for a smarter solution like: > > for i[:2] in list: > > > etc. or by doing some looping over loop. > Do not worry I'll work out the answer. > > Wishing you a happy day ahead, > Regards, > Subhabrata. > -- > http://mail.pyt

Re: How to iterate the input over a particular size?

2009-12-28 Thread Peter Otten
Francesco Bochicchio wrote: > Not sure I understood your question, but if you need just to plit a > big list in sublists of no more than 9 elements, then you can do > someting like: > > def sublists(biglist, n ): > "Splits a big list in sublists of max n elements" > prev_idx = 0;

Re: How to iterate the input over a particular size?

2009-12-28 Thread Francesco Bochicchio
On 27 Dic, 22:29, joy99 wrote: > On Dec 27, 8:42 pm, Benjamin Kaplan wrote: > > > > > On Sun, Dec 27, 2009 at 9:44 AM, joy99 wrote: > > > Dear Group, > > > > I am encountering a small question. > > > > Suppose, I write the following code, > > > > input_string=raw_input("PRINT A STRING:") > > > s

Re: How to iterate the input over a particular size?

2009-12-27 Thread joy99
On Dec 27, 8:42 pm, Benjamin Kaplan wrote: > On Sun, Dec 27, 2009 at 9:44 AM, joy99 wrote: > > Dear Group, > > > I am encountering a small question. > > > Suppose, I write the following code, > > > input_string=raw_input("PRINT A STRING:") > > string_to_word=input_string.split() > > len_word_list

Re: How to iterate the input over a particular size?

2009-12-27 Thread Benjamin Kaplan
On Sun, Dec 27, 2009 at 9:44 AM, joy99 wrote: > Dear Group, > > I am encountering a small question. > > Suppose, I write the following code, > > 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: >             r

Re: How to iterate the input over a particular size?

2009-12-27 Thread Shawn Milochik
A couple of notes: Your code is too packed together. That makes it hard to read. Put in some whitespace (and comments, where necessary), and put spaces around your equal signs (x = 23 instead of x=23). That said, here's something I threw together: #!/usr/bin/env python def chop_list(words, si

How to iterate the input over a particular size?

2009-12-27 Thread joy99
Dear Group, I am encountering a small question. Suppose, I write the following code, 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_