Created
November 8, 2010 00:29
-
-
Save jamesnvc/667229 to your computer and use it in GitHub Desktop.
Code lab
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
| # Given dictionaries, d1 and d2, create a new dictionary with the following | |
| # property: for each entry (a, b) in d1, if there is an entry (b, c) in d2, then | |
| # the entry (a, c) should be added to the new dictionary. For example, if d1 is | |
| # {2:3, 8:19, 6:4, 5:12} and d2 is {2:5, 4:3, 3:9}, then the new dictionary | |
| # should be {2:9, 6:3} Associate the new dictionary with the variable d3 | |
| d3 = {} | |
| for (k, v) in d1.iteritems(): | |
| if v in d2: | |
| d3[k] = d2[v] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment