[Python-3000] More wishful thinking
Josiah Carlson
jcarlson at uci.edu
Sun Apr 16 16:40:05 CEST 2006
Talin <talin at acm.org> wrote:
>
> Talin <talin <at> acm.org> writes:
>
> > 2) A suggestion which I've seen others bring up before is the use of
> > the * operator for tuple packing / unpacking operations, i.e.:
> >
> > a, *b = (1, 2, 3)
>
> I wanted to add another case that I run across in my code a lot.
>
> I often times want to split off a single leading word or token
> from a string, but I don't know in advance whether or not the
> split will actually succeed.
>
> For example, suppose you want to render the first word of
> a paragraph in a different style:
>
> first, rest = paragraph.split( ' ', 1 )
[snip]
See str.partition in Python 2.5 (I don't know if it is implemented yet
or not).
'Python is fun!'.partition(' ') -> 'Python', ' ', 'is fun'
- Josiah
More information about the Python-3000
mailing list