[Python] shortcut?

Rob Hudson rob at euglug.net
Sun May 21 18:37:22 PDT 2006


Is there a Python shortcut for the following?

if d.has_key(k):
	d[k].append(v)
else:
	d[k] = [v]

I'm keeping a dictionary of key:list pairs and I'm writing the above 
often.  I think I remember seeing a shortcut to something like this but 
I can't recall what it was.

Thanks,
Rob


More information about the Python mailing list