#!/usr/bin/python # Ivan Novick # Dec-25, 2007 # demonstrate set operators # create 4 sets # each set is the numbers from 1-50 that are divisible by 2,3,4,5 respectively twos = set([2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50]) threes = set([3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48]) fours = set([4,8,12,16,20,24,28,32,36,40,44,48]) fives = set([5,10,15,20,25,30,35,40,45,50]) # union of fours and fives a = fours | fives print "union of 4s and 5s: ", a # intersection of twos and threes b = twos & threes print "intersection of 2s and 3s: ", b # difference between fours and fives c = fours - fives print "items in 4s but not 5s: ", c # items in twos or fours but not both d = twos ^ fours print "items in 2s or 4s but not both: ", d