Scott David Daniels wrote:
> iter(elem in lst if elem[3] == x).next()
>
> Does this look any better? At least it stops when the answer is found.
Next time you'll recommend
if (a>b) == True:
# ...
Watch out, you're on a slippery slope here :-)
Peter
--
http://mail.python.org/mailman/li
Peter Otten wrote:
> Repton wrote:
>
> > I often find myself storing data in a list of tuples, and I want to ask
> > questions like "what is the index of the first tuple whose 3rd element
> > is x", or "give me the first tuple whose 2nd element is y".
> >>> items = [(1, "a", 10), (2, "b", 20), (3,
Peter Otten wrote:
> Repton wrote:
>
>>I often find myself storing data in a list of tuples, and I want to ask
>>questions like "what is the index of the first tuple whose 3rd element
>>is x",
iter(n for n, elem in enumerate(lst) if elem[3] == x).next()
>>or "give me the first tuple whose 2
Repton wrote:
> I often find myself storing data in a list of tuples, and I want to ask
> questions like "what is the index of the first tuple whose 3rd element
> is x", or "give me the first tuple whose 2nd element is y".
>
> I know I can do [elem for elem in lst if elem[3] == x][0] or (elem for
Repton wrote:
> I often find myself storing data in a list of tuples, and I want to ask
> questions like "what is the index of the first tuple whose 3rd element
> is x", or "give me the first tuple whose 2nd element is y".
>
> I know I can do [elem for elem in lst if elem[3] == x][0] or (elem for
I often find myself storing data in a list of tuples, and I want to ask
questions like "what is the index of the first tuple whose 3rd element
is x", or "give me the first tuple whose 2nd element is y".
I know I can do [elem for elem in lst if elem[3] == x][0] or (elem for
elem in lst if elem[2] =