You can modify your code to stop trying to split the 'remaining part'
when the 'remaining part' is too small
def strsplit(stri, spa):
if len(stri) <= spa:
final_result.append(stri)
return
s = stri[:spa]
final_result.append(s)
stri = stri[spa:]
strsplit(stri,spa
check length of input string with if stri.len > 3
On Sun, Jun 5, 2011 at 8:35 PM, Ganapathy Subramanium <
sganapathy.subraman...@gmail.com> wrote:
> Hi All,
>
> I'm a new bie to programming and need some assistance in this code.
>
> I have a function which will split the given string into 3 chara
Hi All,
I'm a new bie to programming and need some assistance in this code.
I have a function which will split the given string into 3 characters each
and I want to achieve this by recursion.
I have written the following code, but I don't know how to stop the
recursion when the length of the rem
On Wed, 20 Aug 2008 06:16:17 -0700, MRAB wrote:
> So it's defined behaviour that an exhausted iterable will always raise
> StopIteration no matter how many times it's asked for the next value?
Be careful -- an iterable is not the same as an iterator.
Iterables are anything that you can iterate o
MRAB wrote:
> So it's defined behaviour that an exhausted iterable will always raise
> StopIteration no matter how many times it's asked for the next value?
That is not enforced. However, quoting
http://www.python.org/dev/peps/pep-0234/
"""
Iterator implementations (in C or in Python) should gua
On Aug 20, 11:27 am, John Machin <[EMAIL PROTECTED]> wrote:
> On Aug 20, 7:56 pm, MRAB <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Aug 20, 12:11 am, John Machin <[EMAIL PROTECTED]> wrote:
>
> > > or, perhaps, for completeness/paranoia/whatever:
>
> > > it = iter(iterable)
> > > try:
> > > headings =
On Aug 20, 7:56 pm, MRAB <[EMAIL PROTECTED]> wrote:
> On Aug 20, 12:11 am, John Machin <[EMAIL PROTECTED]> wrote:
>
> > or, perhaps, for completeness/paranoia/whatever:
>
> > it = iter(iterable)
> > try:
> > headings = it.next() # < 2.5
> > except StopIteration:
> > # code to handle empty
>
On Aug 20, 12:11 am, John Machin <[EMAIL PROTECTED]> wrote:
> On Aug 20, 5:06 am, Terry Reedy <[EMAIL PROTECTED]> wrote:
>
> > In your case, the standard Python idiom, as Jon said, is
>
> > it = iter(iterable)
> > next(it) # 2.6, 3.0
> > for for item in iterable:
> > f(item)
>
> or, perhaps, for
On Aug 20, 5:06 am, Terry Reedy <[EMAIL PROTECTED]> wrote:
> In your case, the standard Python idiom, as Jon said, is
>
> it = iter(iterable)
> next(it) # 2.6, 3.0
> for for item in iterable:
>f(item)
or, perhaps, for completeness/paranoia/whatever:
it = iter(iterable)
try:
headings = it.n
ssecorp wrote:
I want a parse a file of the format:
movieId
customerid, grade, date
customerid, grade, date
customerid, grade, date
etc.
so I could do with open file as reviews and then for line in reviews.
but first I want to take out the movie id so I use an iterator.
then i want to iterat
On Tue, Aug 19, 2008 at 7:39 PM, ssecorp <[EMAIL PROTECTED]> wrote:
> I want a parse a file of the format:
> movieId
> customerid, grade, date
> customerid, grade, date
> customerid, grade, date
> etc.
>
> so I could do with open file as reviews and then for line in reviews.
>
> but first I want to
On Aug 19, 12:39 pm, ssecorp <[EMAIL PROTECTED]> wrote:
> I want a parse a file of the format:
> movieId
> customerid, grade, date
> customerid, grade, date
> customerid, grade, date
> etc.
>
> so I could do with open file as reviews and then for line in reviews.
>
> but first I want to take out th
On Aug 19, 7:39 am, ssecorp <[EMAIL PROTECTED]> wrote:
> I want a parse a file of the format:
> movieId
> customerid, grade, date
> customerid, grade, date
> customerid, grade, date
> etc.
>
> so I could do with open file as reviews and then for line in reviews.
>
> but first I want to take out the
I want a parse a file of the format:
movieId
customerid, grade, date
customerid, grade, date
customerid, grade, date
etc.
so I could do with open file as reviews and then for line in reviews.
but first I want to take out the movie id so I use an iterator.
then i want to iterate through all the r
14 matches
Mail list logo