python 编程: 请高手帮我解答python function (提示:不能超过2行)

来源:百度知道 编辑:UC知道 时间:2024/06/09 02:33:45
1) You are given a variable, wwII_battle_winners , that is associated with a dictionary that maps the names of World War II battles to the victors of WWII battles. Write some code that associates a sorted list of the battle names that appear as keys in this dictionary with the variable battles .

2)The inverse of a map is a new map where the values of the original map become the keys of the new map and the keys become the values. For example, given the map {1:2, 3:4} , the inverse is the map {2:1, 4:3} . Given the map, d , create the inverse of d . Associate the new map with the variable inverse . You may assume that there are no duplicate values in d (that is no two keys in d map to the same value).

1) result = sorted([x for x in wwII_battle_winners.keys()])

2) inverst = dict((v,k) for k,v in d.items())

不是"高手", 还望真"高手"指教 :)

好像挺难的哦~~~这些字典之类的我常搞错呢