0

[SOLVED] Python Lamda expression to see if item exists in array

I was hoping for a Lamda expression to see if an item exists with an array. E.g. [cat,dog,pig,hair] is there a lion true false? [Edit] So the problem was a bit more complex than I realized it would actually be [the cat went shops,the dog ran] is cat in there?

21st Aug 2020, 8:47 AM
Charlie Crease-huggett
2 ответов
+ 2
Something like this ? a=["lion","tiger","deer"] print(list(map(lambda x:True if "lion" in x else False,a)))
21st Aug 2020, 9:12 AM
Abhay
Abhay - avatar
+ 1
I managed to concatenate the string to the right format and use the if statement above. Thanks ~ swim ~
21st Aug 2020, 1:38 PM
Charlie Crease-huggett