Created
August 12, 2013 15:29
-
-
Save cizixs/6211891 to your computer and use it in GitHub Desktop.
This gist lists some pythonic dict manipulation from Python Cookbook.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def addItem(theIndex, word, pagenumber): | |
| theIndex.setdefault(word, [ ]).append(pagenumber) | |
| #the above method equals to the following | |
| def addItem(theIndex, word, pagenumber): | |
| if word in theIndex: | |
| theIndex[word].append(pagenumber) | |
| else: | |
| theIndex[word] = [pagenumber] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment