how to implement built-in sum() of the class?
A built-in function sum() applied to a dictionary returns the sum of its
keys:
sum({1:0,2:10})=3
I'd like to create a subclass of the dictionary, say SubDict, and override
some function to return the sum of its values, i.e.
sum(SubDict((1,0),(2,10))=10
Which function do I need to override to achieve this functionality?
p.s. this is a general question, how to implement the built-in sum()
function to a class, not just in this particular case.
No comments:
Post a Comment