Reputation: 1131
lst = {}
try:
lst[someKey].append(someValue)
except KeyError:
lst[someKey] = []
lst[someKey].append(someValue) # redundant ?
Is there a better way to add to a non-existing key ? In PHP etc it'll create it on its own.
Upvotes: 1
Views: 198