How to define list of int and defaultdict
Question: I want to define a list of an integer and defaultdict in python. I am creating
a parent dictionary which shall return the above list.

I am being unable to define the list type.

    
    
    def index_struct():return defaultdict(list_struct)
    def list_struct(): return list(int,post_struct)
    def post_struct(): return defaultdict(list)
    

Currently getting an error as list cant take two args..

Thanks for the help in advance


Answer: You're right that _list()_ only takes one argument. Use the square brackets
notation instead. Also note the `[int, post_struct]` won't work because
nothing is calling the two constructors. You need to call the constructors
manually by adding parentheses:

    
    
    from collections import defaultdict
    
    def index_struct():return defaultdict(list_struct)
    def list_struct(): return [int(), post_struct()]
    def post_struct(): return defaultdict(list)
    
    >>> d = index_struct()
    >>> d['somekey'][0] = 5
    >>> d['somekey'][1]['anotherkey'] = 6
    >>> d
    defaultdict(<function list_struct at 0x10252ff50>, {'somekey': [5, defaultdict(<type 'list'>, {'anotherkey': 6})]})
    

