I have a standard exercise in sharing Python's data structures, wherein I bury the string "Waldo" in some deeply nested object, say as an element in a tuple in a dict in a list... to some demented level.[1]
When we're learning Python grammar, that's when "demented" makes sense i.e. this isn't about writing production code so much as getting the basic principles. Along similar lines, when introducing super() and the method resolution order, I'm often looking for a class hierarchy that (A) involves multiple inheritance, (B) is several levels deep and (C) has "diamond patterns". Finally it hit me: I could turn to the Book of Genesis for a family tree with all these features, plus the advantage of being easy to lookup. Adam and Eve had several kids (they lived enormously long lives by today's standards), and the siblings had to have kids by each other given they were the only humans on the planet. Adam and Eve's son Seth and daughter Azura (two cases of multiple inheritance), had a son (another case). Also, Noah's mom goes back to a great grandparent shared with his dad. Diamond pattern. Eureka. There's already some precedent in mixing CS with bible studies (thinking of Knuth), and besides, Python is heavily used in the humanities for natural language processing. Bridging from Python to Genesis doesn't seem too far-fetched. :-D http://nbviewer.jupyter.org/github/4dsolutions/SAISOFT/blob/master/OO_Paradigm.ipynb (see "Multiple Inheritance") There "where's Waldo" exercise and this investigation into the MRO may be combined: bury a waldo() instance or class method somewhere in the Genesis family try, in a couple places and go: >>> subject = Noah() >>> subject.waldo() to find out where the name resolves. Have the waldo method report on its class. Kirby Cross reference to connected edu-sig topic: Rich Data Structures [1] Example code: # -*- coding: utf-8 -*- """ Created on Mon Apr 17 17:23:45 2017 @author: Kirby Urner Example of the "Where's Waldo" genre: https://i.ytimg.com/vi/SiYrSYd7mlc/maxresdefault.jpg Extract "Waldo" from each data structure """ data = {"id:":["Joe", "Smith"], "mother": ["Judy", "Smith"], "father": ["Waldo", "Smith"]} waldo = "???" # output "Waldo" print(waldo) #============================ data = {"Waldo": {"scores":[34,56,23,98,89]}} waldo = "???" # output "Waldo" hint: dict.keys() print(waldo) #============================ data = {(1,2):{"Name":["Waldeen", "Smith"]}, (4,5):{"Name":["Waldorf", "Smith"]}, (9,0):{"Name":["Waldo", "Smith"]}} waldo = "???" # output "Waldo" hint: tuples may be keys print(waldo) #============================ data = ["Joe", 3, 7, ["dog", ("cat", "Waldo")], 27, {}] waldo = "???" print(waldo) # output "Waldo' #============================ data = ([], [], ()) data[1].append("Wendy") data[1].append("Waldo") data[1].append("Willow") # where's Waldo? waldo = "???" # <your answer> print(waldo) # NOW MAKE UP SOME OF YOUR OWN!
_______________________________________________ Edu-sig mailing list Edu-sig@python.org https://mail.python.org/mailman/listinfo/edu-sig