t306.py 710 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Test set unions
  2. # sets are un-ordered, though python seems to sort them sometimes...
  3. # hence the testing for equality to known sets rather than printing.
  4. s = set([2,3,4])
  5. t = set([4,5,6])
  6. u = set([1,2,3,4,5])
  7. print s
  8. print t
  9. print u
  10. print '# pair unions'
  11. a = s.union(t)
  12. b = s.union(u)
  13. c = t.union(s)
  14. d = t.union(u)
  15. e = u.union(s)
  16. f = u.union(t)
  17. print a == c
  18. print a == set([2,3,4,5,6])
  19. print b == e
  20. print b == set([1,2,3,4,5])
  21. print d == f
  22. print d == set([1,2,3,4,5,6])
  23. print '# triple unions'
  24. a = s.union(t, u)
  25. b = s.union(u, t)
  26. c = t.union(s, u)
  27. d = t.union(u, s)
  28. e = u.union(s, t)
  29. f = u.union(t, s)
  30. print f
  31. print a == set([1,2,3,4,5,6])
  32. print a == b
  33. print a == c
  34. print a == d
  35. print a == e
  36. print a == f