2014-12-17 5 views
-4

У меня есть следующий список кортежей.Найти элемент в списке кортежей в python

[('rel', 'dns-prefetch'), ('href', 'http://g-ecx.images-amazon.com')] 
[('rel', 'dns-prefetch'), ('href', 'http://z-ecx.images-amazon.com')] 
[('rel', 'dns-prefetch'), ('href', 'http://ecx.images-amazon.com')] 
[('rel', 'dns-prefetch'), ('href', 'http://completion.amazon.com')] 
[('rel', 'dns-prefetch'), ('href', 'http://fls-na.amazon.com')] 
[('rel', 'stylesheet'), ('href', 'http://z-ecx.images- amazon.com/images/G/01/AUIClients/NavAuiAssets-bc93e610a616dd196eda0cc0238d74dd3f830199.min._V2_.css')] 
[('rel', 'stylesheet'), ('href', 'http://z-ecx.images-amazon.com/images/G/01/AUIClients/AmazonUI-c0d0f2a115191b947c48fd97b453a95d32cbadc0.rendering_engine-not-trident.weblab-AUI_CSS_REDUCTION_28708-T1.weblab-AUI_HIGH_CONTRAST_40800-T1.min._V2_.css')] 
[('rel', 'stylesheet'), ('href', 'http://z-ecx.images-amazon.com/images/G/01/AUIClients/AmazonGatewayAuiAssets-0320163872407ddbb58566fd72a492fca3b17ed4.min._V2_.css')] 
[('rel', 'canonical'), ('href', 'http://www.amazon.com/')] 

Мне нужно найти элемент в них. Я делаю.

for attr in attrs: 
    #Need a code here to find an element without iterating over attar. 

Есть ли способ сделать это в Python.

+1

Что логика для найти этот элемент? – Kasramvd

+0

Отправьте пример, чтобы лучше понять проблему ... –

ответ

0

Вы можете использовать in для проверки членства:

>>> for attr in attrs: 
... if ('href', 'http://fls-na.amazon.com') in attr: 
...  print attr 
... 
[('rel', 'dns-prefetch'), ('href', 'http://fls-na.amazon.com')] 
Смежные вопросы