1 回答

TA貢獻1828條經驗 獲得超3個贊
我假設數據結構是這樣的:
['gameX', 'useless_info', 'genreX', 'info', 'info', ...]
我想如果兩個列表上的數據結構相同,那么將兩個列表相加并僅交互一次會更容易,對吧?
complete_list = list_of_data1 + list_of_data2
# make one list with all the data
dict_games = {genre : {} for genre in set([x[2] for x in complete_list])}
# make a dict of dict with all genres
for game, _, genre, *info in complete_list:
if game in dict_games[genre]:
# check if the game exits on both list of data and sum the info
info = info + dict_games[genre][game]
dict_games[genre].update({game: info})
如果您想對兩個列表中出現的同一游戲的信息進行求和,我認為這是最簡單的方法。但如果你想丟棄信息,那么你可以按優先級對數據列表求和,或者如果你想創建一些規則來丟棄信息,那么我建議在數據結構上附加一個標志,并在稍后更新 dict_games 時使用它。請告訴我它是否有效或者是否有什么不太清楚。
添加回答
舉報