Getting a list value from key/value pair
Thomas Jollans
t at jollybox.de
Sun Sep 18 06:16:09 EDT 2011
On 18/09/11 11:39, Kayode Odeyemi wrote:
> Hi all,
>
> If I have a list with key/value pair, how do I get the value of the key?
>
> I'm working with this code snippet:
Python 3.2.2 (default, Sep 5 2011, 04:33:58)
[GCC 4.6.1 20110819 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> lst = [ ('key1', 'value1'), ('key2', 'value2') ]
>>> d = dict (lst)
>>> d['key1']
'value1'
>>>
>
>>>> items = {'fees':[('status','pending'), ('timeout',60)],
> 'hostel':[('status',
> 'pending'), ('timeout','120')]}
>>>> print [items[i] for i in items.keys()]
> [[('status', 'pending'), ('timeout', '120')], [('status', 'pending'),
> ('timeout'
> , 60)]]
>>>>
>
> --
> Odeyemi 'Kayode O.
> http://www.sinati.com. t: @charyorde
>
>
>
More information about the Python-list
mailing list