[Python-ideas] min_fields argument to str.split()

Vitor Bosshard algorias at yahoo.com
Wed Jan 21 15:14:57 CET 2009


MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

----- Mensaje original ----=0A> De: Mathias Panzenb=F6ck <grosser.meister.m=
orti at gmx.net>=0A> Para: Arnaud Delobelle <arnodel at googlemail.com>=0A> CC: p=
ython-ideas at python.org=0A> Enviado: mi=E9rcoles, 21 de enero, 2009 10:55:08=
=0A> Asunto: Re: [Python-ideas] min_fields argument to str.split()=0A> =0A>=
 Arnaud Delobelle schrieb:=0A> >=0A> > How about this?=0A> >=0A> >>>> from =
itertools import *=0A> >>>> def fixlen(iterable, len, item=3DNone):=0A> > .=
..=A0 =A0 return islice(chain(iterable, repeat(item)), len)=0A> > ...=0A> >=
>>> list(fixlen([1, 2, 3], 5))=0A> > [1, 2, 3, None, None]=0A> >=0A> =0A> I=
 like this. Maybe an addition to itertools?=0A> =0A> +1=0A=0A+1 from me too=
.=A0Way better than the generator I proposed. Having this as a function als=
o makes it=A0applicable to much more than just one use case.=0A=0AIf you se=
e the following code:=0A=0Aa,b,c,d =3D fixlen(str.split(),4)=0A=0Ayou immed=
iately know it's not a regular unpacking operation; it will be the first pl=
ace you look if something goes wrong.=0A=0A=0AVitor=0A=0A=0A      =A1Todo s=
obre la Liga Mexicana de f=FAtbol! Estadisticas, resultados, calendario, fo=
tos y m=E1s:<=0Ahttp://espanol.sports.yahoo.com/



More information about the Python-ideas mailing list