Can this Python code be shortened and still be readable using itertools and sets?
result = {} for widget_type, app in widgets: if widget_type not in result:
You can use a defaultdict(list).
defaultdict(list)
from collections import defaultdict result = defaultdict(list) for widget_type, app in widgets: result[widget_type].append(app)