help wanted with list

Simon Brunning simon at brunningonline.net
Thu Sep 24 22:46:56 CEST 2009


2009/9/24 Ahmed Shamim <partha.shamim at gmail.com>:
> list = [ 'a', '1', 'b', '2']
> what would be the logic, if I input a to get output 1.

Turn it into a dictionary first:

>>> mylist = [ 'a', '1', 'b', '2']
>>> mydict = dict(zip(mylist[::2], mylist[1::2]))
>>> mydict['a']
'1'

-- 
Cheers,
Simon B.



More information about the Python-list mailing list