我想要在Python字典中将键(key)变为值(value),但原始字典中的值不唯一。
这是我的代码:
year_person = {2000: ‘Linda’, 2001: ‘Ron’, 2002: ‘Bruce’, 2003: ‘Linda’, 2004: ‘Bruce’, 2005 ‘Gary’, 2006: ‘Linda’}
This is what I want to change it to:
person_year = {‘Linda’: 2000, ‘Ron’: 2001, ‘Bruce’: 2002, ‘Linda’, 2003: ‘Bruce’, 2004 ‘Gary’, 2005: ‘Linda’: 2006}
当我尝试使用for循环进行转换时,每个人只能匹配到一个相应的对。