CodeLab Solution 51265




CS101 CodeLab Solutions

CodeLab Solution 51265

Given a dictionary d, create a new dictionary that reverses the keys and values of d. Thus, the keys of d become the values of the new dictionary and the values of d become the keys of the new dictionary. You may assume d contains no duplicate values (that is, no two keys map to the same values.) Associate the new dictionary with the variable inverse.

[cc lang=”PYTHON”] inverse={x:y for y,x in d.items()}
[/cc]

 

No Comments Yet.

Leave a comment

You must be Logged in to post a comment.