Alex Rivera | Logout

Python, find out that a list does not have specific item

Asked 2010-12-15T14:07:39.897
15

Let's say there is a list a that contains both numbers and letters. Is there quick way to find out that the list doesn't contain some specific element. I plan to use it in conditions.

Edit
Report

1 Answer

3

Note: If you can put the elements as keys of a dict then testing for membership is much quicker thanks to the hashing algorithm. Will only be an issue if your list is very long or your app does a lot of this kind of thing. Otherwise, "X not in Y" as Sven says.

answered 2010-12-15T14:11:07.197

Your Answer