Hi all, My first post ever! :) I'm following the guide "Learn Python the Hard Way" and have reached a point where I am struggling to understand the code and unfortunately the authors guide hasn't cleared it up for me. (excercise 40 for reference)
The main confusion is coming from* 'cities['_find'] = find_city'* I'm not sure what this is really doing. >From my learning, this should add an extra item to the dict with the index name of "_find" and the value which is returned from "find_city" function. run I add "print cities" after the above function to try and look at how the dict is now populated, I am still confused. (PasteBin version to see highlighting and indents -> http://pastebin.com/gmngh6sc Not sure how it will look in email) ------------------ cities = {'ca': 'San Fran','MI':'detroit','FL':'Jacksonville'} cities['NY']= 'New York' cities['OR']= 'Portland' def find_city(themap, state): if state in themap: return themap[state] else: return "Not found" cities['_find'] = find_city while True: print "State? (Enter to quit)", state = raw_input("> ") if not state: break city_found = cities['_find'](cities,state) print city_found ---------------------- Grateful for any help in explaining how this program is working and each step it is taking. kindest regards Robert
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor