[Tutor] working with multiple sets

kevin parks kp8 at me.com
Tue Sep 8 18:40:31 CEST 2009


I guess what i honestly want to asks, but am hesitant to since it  
makes me look like a dork is:

What would this look like if i want to use a straight up built-in  
dictionary type and not the collections.defaultdict.


import collections

def foo():
	lookup = collections.defaultdict(list)
	x = range(10)
	y = range(5, 15)
	z = range(8, 22)
	sets = {'x': set(x), 'y': set(y), 'z': set(z)}
	for key, value in sets.items():
		for element in value:
			lookup[element].append(key)
	print "\n", lookup, "\n\n"
	for x in lookup:
		lookup[x].sort()
		print x, lookup[x]
	print "\n"




More information about the Tutor mailing list