[Edu-sig] Easter Egg Hunt
kirby urner
kirby.urner at gmail.com
Fri Mar 9 02:09:55 CET 2007
Here's a kind of little puzzle you can use with your students
to motivate their understanding of nested collections.
Given 'hunt' what subscripts will get you the egg?
>>> hunt = [({"easter":[1,2,{(3,4):"egg","chocolate":[(1,'bunny')]}]},())]
Answer:
>>> hunt[0][0]["easter"][2][(3,4)]
'egg'
Variations on that theme. Not as hard as it looks, if you let them
drill down using some trial and error:
>>> hunt[0][0]
{'easter': [1, 2, {(3, 4): 'egg', 'chocolate': [(1, 'bunny')]}]}
>>> hunt[0][0]["easter"]
[1, 2, {(3, 4): 'egg', 'chocolate': [(1, 'bunny')]}]
>>> hunt[0][0]["easter"][2]
{(3, 4): 'egg', 'chocolate': [(1, 'bunny')]}
>>> hunt[0][0]["easter"][2][(3,4)]
'egg'
Kirby
More information about the Edu-sig
mailing list