2014-12-17 8 views
-4

다음 튜플 목록이 있습니다.파이썬의 튜플 목록에서 요소 찾기

[('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. 

파이썬에서이를 수행 할 수있는 방법이 있습니까?

+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')] 
관련 문제