Python 在元组列表中搜索

Python 在元组列表中搜索,python,Python,我提取一个数据集行: (u"[('x-xss-protection', '1; mode=block'), ('x-powered-by', 'PHP/5.4.21 ZendServer/6.2.0'), ('transfer-encoding', 'chunked'), ('expires', '0'), ('vary', 'Accept-Encoding'), ('server', 'nginx'), ('last-modified', 'Thu, 03 Dec 2015 10:20:02

我提取一个数据集行:

(u"[('x-xss-protection', '1; mode=block'), ('x-powered-by', 'PHP/5.4.21 ZendServer/6.2.0'), ('transfer-encoding', 'chunked'), ('expires', '0'), ('vary', 'Accept-Encoding'), ('server', 'nginx'), ('last-modified', 'Thu, 03 Dec 2015 10:20:02 GMT'), ('connection', 'keep-alive'), ('pragma', 'no-cache'), ('cache-control', 'must-revalidate, post-check=0, pre-check=0, public'), ('date', 'Thu, 03 Dec 2015 10:20:02 GMT'), ('x-cached', 'EXPIRED'), ('content-type', 'text/html')]",)
我想找到“内容类型”。 我试过dict,list,enumerate,str。。。
但是什么都不起作用:(

元组中的字符串看起来像一个列表,我建议使用它将其转换为一个真正的列表,然后将其转换为dict(只需运行
dict()
函数),并使用
'content-type'
作为访问
'text/html'
(值)的键:

输出:

'text/html'

x-xss-protection'
'x-xss-protection'
?这不是一个元组列表。这是一个包含字符串的元组“x-xss-protection”,你是对的。我删除了一些数据:)如果你在数据库中存储这种类型的数据,这就是访问它的方法?@Anonymus:如果数据库中的数据与你的示例类似:是的。否则,你可以问一个新问题。
'text/html'