Skip to content

Instantly share code, notes, and snippets.

@Everfighting
Created September 18, 2018 06:09
Show Gist options
  • Save Everfighting/bcdaadbbfa8cb63f930330bdef785af4 to your computer and use it in GitHub Desktop.
Save Everfighting/bcdaadbbfa8cb63f930330bdef785af4 to your computer and use it in GitHub Desktop.
互换键值位置
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@desc: 互换键值位置
@author: Bingo Cai
"""
prefs = {'Lady in the water':{'Lisa Rose':2.5, 'Gene Seymour':3.0},
'Lady in the moon':{'Lisa Rose':3.5, 'Gene Seymour':2.0},
'spring festival':{'Lisa Rose':1.5, 'Gene Seymour':1.0},
'happy everyday':{'Lisa Rose':3.5, 'Gene Seymour':4.0},
}
def transformPrefs(prefs):
result = {}
for person in prefs:
for item in prefs[person]:
result.setdefault(item, {})
result[item][person] = prefs[person][item]
print(result)
transformPrefs(prefs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment