Counting number of each item in a list.

Peter Otten __peter__ at web.de
Mon Mar 20 07:27:43 EST 2006


per9000 wrote:

> A good idea could be to change the header of the first one (if you want
> the option to start counting from zero) into:
> def dict_add(inlist,indict={},init=1):

make that

def dict_add(inlist, indict=None, init=1):
    if indict is None:
        indict = {}

See "5. Mutable default arguments" at
http://zephyrfalcon.org/labs/python_pitfalls.html for an explanation.

Peter



More information about the Python-list mailing list