No strides? (was Re: List mapping?)
David Smith
drs at labs.agilent.com
Fri Apr 14 14:12:13 EDT 2000
Why aren't strides implemented for slices of lists and tuples? I would
have liked to suggest
map( None, a[0::2], a[1::2] )
David Smith
Nick Trout wrote:
>
> Is there a nice way of pairing up the members to form tuple pairs in another
> list? ie. like you might to processing input args.
>
> ie. changing ['/a','1','/b','2','/c','3'] into [ ('/a','1'), ('/b','2'),
> ('/c','3') ]
>
> eg:
>
> args = '/a 1 /b 2 /c 3'
> listargs= string.split(args)
> tuplist = []
> i=0
> while i < len(listargs):
> tuplist.append( (listargs[i],listargs[i+1]) )
> i = i+2
> for i in tuplist:
> processargs(i)
>
> or:
>
> args = '/a 1 /b 2 /c 3'
> for i in string.split(args):
> i = argflag
> # i want next arg now as a parameter!!!
>
> Can I (you!) get rid of the long winded while loop cleverly?!! :-)
>
> Thanks in advance,
> Nick.
More information about the Python-list
mailing list