Questo codice Python può essere abbreviato e può essere ancora letto con itertools e set?Creare o aggiungere a un elenco in un dizionario - può essere abbreviato?
result = {}
for widget_type, app in widgets:
if widget_type not in result:
result[widget_type] = []
result[widget_type].append(app)
posso pensare a questo solo:
widget_types = zip(*widgets)[0]
dict([k, [v for w, v in widgets if w == k]) for k in set(widget_types)])
mai saputo di questo. Freddo! –