in Operator

  1. >>> x = [1, 3, 6, 193]
  2. >>> 6 in x
  3. True
  4. >>> 7 in x
  5. False
  6. >>> y = { 'Jim' : 'gray', 'Zoe' : 'blond', 'David' : 'brown' }
  7. >>> 'Jim' in y
  8. True
  9. >>> 'Fred' in y
  10. False
  11. >>> 'gray' in y
  12. False

any Opeator

any is a boolean function that returns True if any element of the given iterable evaluates to True. This can seem a little silly until you remember your list comprehensions! Combining these any and in can produce powerful, clear syntax for many situations:

  1. >>> my_big_list = [10, 23, 875]
  2. >>> my_small_list = [1, 2, 8]
  3. >>> any([x < 3 for x in my_big_list])
  4. False
  5. >>> any([x < 3 for x in my_small_list])
  6. True