shanenin Posted August 14, 2005 Report Share Posted August 14, 2005 lets say I have a list called lislis = [(1, 2), (3, 4), (5, 6), (7, 8)]lets say I want to test for a numner in the first position of each tuple. to give you an idea of what I want to do, I will show you code that does not work, but might make my pointif 3 in lis[0-3][0]:the code would read if 3 is in the first position of the first four tuples: Quote Link to post Share on other sites
jcl Posted August 14, 2005 Report Share Posted August 14, 2005 (edited) Hmm. My inclination would be to use mapif 3 in map(lambda(t): t[0], lis):, but kind of thing is discouraged in Python these days, or a list comprehensionif [i for i in lis if i[0] == 3]:but neither is very efficient. Edited August 14, 2005 by jcl Quote Link to post Share on other sites
shanenin Posted August 14, 2005 Author Report Share Posted August 14, 2005 (edited) thanks. I like the list comprehension. That is sure to come in handy again.I did it this wayif 3 in [ i[0] for i in lis ]: Edited August 14, 2005 by shanenin Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.