I use the following to check if item
is in my_list
:
if item in my_list:
print("Desired item is in list")
Is "if item in my_list:
" the most "pythonic" way of finding an item in a list?
EDIT FOR REOPENING: the question has been considered duplicate, but I'm not entirely convinced: here this question is roughly "what is the most Pythonic way to find an element in a list". And the first answer to the question is really extensive in all Python ways to do this.
Whereas on the linked duplicate question and its corresponding answer, the focus is roughly only limited to the 'in' key word in Python. I think it is really limiting, compared to the current question.
And I think the answer to this current question, is more relevant and elaborated that the answer of the proposed duplicate question/answer.