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?
3 odpowiedzi
+ 2
Something like this ?
a=["lion","tiger","deer"]
print(list(map(lambda x:True if "lion" in x else False,a)))
+ 1
I managed to concatenate the string to the right format and use the if statement above. Thanks ~ swim ~