like a "for loop" for a string

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Mon Aug 18 00:24:06 CEST 2008


MRAB:
> If it was introduced into Python v3.x then wouldn't it have to be
> called str.split in order to be consistent with xrange -> range? :-)

xsplit may be a name fit for Python 2.6/2.7.

Regarding Python 3.0 you may be right, but then when you want the list
of parts you have to do:
list(somestring.split())

While to count the number of parts on Python 3.0 this may suffice:
sum(1 for part in somestring.split())

Unless you use a leniter() function that counts the lazy iterations
(its functionality can be folded inside the len() too, like in some
lazy languages).

Most of the times I think a lazy splitting may suffice, so in Python
3.0 the eager version may be absent :-)

Bye,
bearophile



More information about the Python-list mailing list