Getting a list value from key/value pair

Kayode Odeyemi dreyemi at gmail.com
Sun Sep 18 12:50:53 CEST 2011


On Sun, Sep 18, 2011 at 11:25 AM, Vincent Vande Vyvre <
vincent.vandevyvre at swing.be> wrote:

> **
> Le 18/09/11 11:39, Kayode Odeyemi a écrit :
>
> 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:
>
> >>> 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
>
>  Sorry, for python3.x
>
> # -*- coding: utf-8 -*-
>
>
> d = {'fees':[('status','pending'), ('timeout',60)], 'hostel':[('status',
>  'pending'), ('timeout','120')]}
>
> for key, value in d.items():
>
>     print("\n {0}".format(key))
>     for val in value:
>         print("\t{0}:  {1}".format(val[0], val[1]))
>
> Very helpful! I gave your karma at
http://stackoverflow.com/questions/7460675/getting-a-list-value-from-key-value-pair

-- 
Odeyemi 'Kayode O.
http://www.sinati.com. t: @charyorde
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110918/61790198/attachment.html>


More information about the Python-list mailing list