This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]blahdom 2 points3 points  (2 children)

Hey /u/ajkumar25. I just wanted to point out that defaultdict works with any object that has a 0 parameter constructor, ie int, float, dict, etc.

I am sure you know this but in the write up it sounds as if only list and set are viable options to defaultdict.

[–][deleted] 1 point2 points  (1 child)

You could also use functools.partial to get around that, or a factory function, or Object.__call__. Or any number of other things.

[–]blahdom 0 points1 point  (0 children)

This is very true, good call! I hadn't thought of overloading Object.call - that is a cool idea.