Pythonic Way to reverse nested dictionaries

后端 未结 5 1748
旧巷少年郎
旧巷少年郎 2020-12-14 11:46

I have a nested dictionary of people and item ratings, with people as the key. people may or may not share items. Example:

{
 \'Bob\' : {\'item1\':3, \'item2         


        
5条回答
  •  甜味超标
    2020-12-14 12:01

    This is easy enough to do (as others have shown), but depending on your needs you should also consider that for data with several pieces of information where you want to extract by any criterion, a database might be the best tool. The built-in sqlite3 module provides a low-overhead database that may, depending on what you are doing, serve you better than a nested dict.

提交回复
热议问题