次のように辞書を作成したい -
{'a':[1, 2, 3, 4, 5], 'b':[1, 3, 5], 'c':[2, 3, 5]}
私が実装した方法は
mydict = dict()
letters = ['a', 'b', 'a', 'c', 'a']
#please mark the list has multiple occurence of a,
#hence I would want to check if a key with 'a' exists. Please do not advise to make the list unique.
for l in letters:
if not mydict.get(l):
mydict[l] = <values from another place via some filter>
else:
mydict[l].append(<values from another dict>)
これを行うためのより良いアプローチはありますか?