Extracting item from list of tuples?
roy at panix.com
Sun Sep 5 19:09:03 CEST 2010
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.
Anyway, I came up with:
location = [t for t in headers if t == 'location']
which works, but is getting on towards the cryptic end of things. Is
there a better idiom for this?
More information about the Python-list