List mapping?

Nick Trout nick at
Thu Apr 13 10:09:52 EDT 2000

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') ]


args = '/a 1 /b 2 /c 3'
listargs= string.split(args)
tuplist = []
while i < len(listargs):
    tuplist.append( (listargs[i],listargs[i+1]) )
    i = i+2
for i in tuplist:


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,

More information about the Python-list mailing list