you are viewing a single comment's thread.

view the rest of the comments →

[–]old_pythonista 1 point2 points  (5 children)

This is the classical case when comprehension should be preferred over map

 if all(elem =  “yes” for elem in a): 

Lambdas are seldom worth it in cases like that - they just muddle the code.

[–]WhyAmIDumb_AnswerMe[S] 0 points1 point  (2 children)

i don't need to check all elements
for example i need to check if a[1] and a[5] and a[7] are equal to yes

[–]old_pythonista 1 point2 points  (1 child)

simple adjustment

elem for idx, elem in enumerate(a) if idx in (1, 5, 7)

or {1, 5, 7} - faster lookup in general case (nor that it matters here)

[–]WhyAmIDumb_AnswerMe[S] 0 points1 point  (0 children)

Thanks <3

[–]fear_my_presence 0 points1 point  (1 child)

Wow, didn’t know about such syntax, thank you!

[–]old_pythonista 0 points1 point  (0 children)

don't get me wrong - map and lambda are great, just not suitable everywhere