Extracting item from list of tuples?

Thomas Jollans thomas at jollybox.de
Sun Sep 5 13:14:44 EDT 2010


On Sunday 05 September 2010, it occurred to Roy Smith to exclaim:
> I'm using httplib, and want to get the Location header from the
> response.  The getheaders() method gives you back a list of (name,
> value) tuples.  It would be a lot more convenient if it gave you back a
> dict, but it is what it is.

It may not be a dict, but you can always make it one: 

>>> L = [('a',1), ('b', 42), ('c', 0)]
>>> dict(L)
{'a': 1, 'c': 0, 'b': 42}
>>> 





More information about the Python-list mailing list