So numbermap.__getitem__ brings back 1, then 2,then 3, then 4. Then it looks up 1 ,2, 3, 4 in month but there is no key with value 1, 2, or or in 4. What am I missing? Thank you very much Monika
---------- Original Message ---------- From: Alan Gauld via Tutor <tutor@python.org> To: tutor@python.org Subject: Re: [Tutor] __getitem__ another problem Date: Wed, 23 Nov 2016 10:09:46 +0000 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 ____________________________________________________________ 7-Time Lotto Winner Reveals The Truth How To Win Any Lottery MNT http://thirdpartyoffers.netzero.net/TGL3241/58358cba68d69cba49c6st04duc _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor