containment.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # sets, see set_containment
  2. for i in 1, 2:
  3. for o in {1:2}, {1:2}.keys():
  4. print("{} in {}: {}".format(i, o, i in o))
  5. print("{} not in {}: {}".format(i, o, i not in o))
  6. haystack = "supercalifragilistc"
  7. for needle in [haystack[i:] for i in range(len(haystack))]:
  8. print(needle, "in", haystack, "::", needle in haystack)
  9. print(needle, "not in", haystack, "::", needle not in haystack)
  10. print(haystack, "in", needle, "::", haystack in needle)
  11. print(haystack, "not in", needle, "::", haystack not in needle)
  12. for needle in [haystack[:i+1] for i in range(len(haystack))]:
  13. print(needle, "in", haystack, "::", needle in haystack)
  14. print(needle, "not in", haystack, "::", needle not in haystack)
  15. print(haystack, "in", needle, "::", haystack in needle)
  16. print(haystack, "not in", needle, "::", haystack not in needle)
  17. # containment of bytes/ints in bytes
  18. print(b'' in b'123')
  19. print(b'0' in b'123', b'1' in b'123')
  20. print(48 in b'123', 49 in b'123')
  21. # containment of int in str is an error
  22. try:
  23. 1 in '123'
  24. except TypeError:
  25. print('TypeError')
  26. # until here, the tests would work without the 'second attempt' iteration thing.
  27. for i in 1, 2:
  28. for o in [], [1], [1, 2]:
  29. print("{} in {}: {}".format(i, o, i in o))
  30. print("{} not in {}: {}".format(i, o, i not in o))