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
_______________________________________________
Edu-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/edu-sig