# Module demonstrates use of lists and set theory principles

def Unite(set1, set2):          # evaluate 2 lists, join both into 1 new list
        newList = []
        for item in set1:
                newList.append(item)
        for item in set2:
                newList.append(item)
        newList.sort()
        return newList

def Intersect(set1, set2):              # evaluate 2 lists, check for
commonalities, output commonalities to 1 new list
        newList = []
        for item in set1:
                if item in set1 and item in set2:
                        newList.append(item)
        newList.sort()
        return newList

def Negate(set1, set2):         # evaluate 2 lists, return negation of 1st list
        newList = []
        for item in set1:
                if item in set2:
                        set1.remove(item)
        newList = set1
        return newList


could this be done in a more elegant fashion?
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to