On 23/11/16 06:26, monik...@netzero.net wrote: > I do not understand how numbermap.__getitem__ brings back month's key.
numbermap returns the integer corresponding to the key. That number is then used by sorted as the basis for sorting month. So for the first entry sorted receives the value 1, for the second it gets 2. and so on. It then prints the keys corresponding to those values. > month = dict(one='January', > two='February', > three='March', > four='April', > five='May') > numbermap = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5} > sorted(month, key=numbermap.__getitem__) > ['one', 'two', 'three', 'four', 'five'] -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor