Find An Element In A List Of Tuples In Python
I have the following list of tuples. [('rel', 'dns-prefetch'), ('href', 'http://g-ecx.images-amazon.com')] [('rel', 'dns-prefetch'), ('href', 'http://z-ecx.images-amazon.com')]
Solution 1:
You can use in
to test membership:
>>> for attr in attrs:
... if ('href', 'http://fls-na.amazon.com') in attr:
... print attr
...
[('rel', 'dns-prefetch'), ('href', 'http://fls-na.amazon.com')]
Post a Comment for "Find An Element In A List Of Tuples In Python"