[ create a new paste ] login | about

Link: http://codepad.org/20iuvZFx    [ raw code | output | fork ]

Python, pasted on Sep 24:
#!/usr/bin/python
def code(lst):
	d = {}
	try:
		for i, l in enumerate(lst):
			if isinstance(l, list):
				for e in l:
					d[e] = i
			elif isinstance(l, dict):
				for e in l.items():
					d[e[0]] = i
					d[e[1]] = i
			else:
				d[l] = i	
	except TypeError, e:
            print "invalid key! "
            print "Check your nested values"
	except Exception, e:
	    print "My Code fault!"
	return d

print code([1, (1, 2), {3: 4}, [5, 6]])


Output:
1
{(1, 2): 1, 1: 0, 3: 2, 4: 2, 5: 3, 6: 3}


Create a new paste based on this one


Comments: