Keeping track of things with dictionaries

Josh English Joshua.R.English at gmail.com
Tue Apr 8 00:02:20 EDT 2014


On Sunday, April 6, 2014 12:44:13 AM UTC-7, Giuliano Bertoletti wrote:


> obj = brands_seen.get(brandname)
> 
> if obj is None:
>     obj = Brand()
>     brands_seen[brandname] = obj
> 
> 

Would dict.setdefault() solve this problem? Is there any advantage to defaultdict over setdefault()

Josh




More information about the Python-list mailing list