[Tutor] (no subject)

Chris Castillo ctcast at gmail.com
Wed Jul 29 19:55:27 CEST 2009


# 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?


More information about the Tutor mailing list