How can I create Dictionary in Python from file, where values are a list
Question: I have a txt file and I want to read values into a dictionary. Different from
common dictionary, the value of each `key` is a value pair, for example:

    
    
    tiger eat meat
    tiger eat people
    rabbit eat carrot
    people can walk
    trees has root
    people has hand
    

I want to get a dictionary that,

    
    
    tiger, {eat, meat}, {eat, people}
    rabbit, {eat, carrot}
    trees, {has, root}
    people, {can, walk}, {has, hand}
    

Should I just `read lines`, `split(\n)` into 3 items and store the first one
as the key and the rest two ones as the values? Or there is a better way to
store the two values?

My objective is that, when I query what does a tiger eat, I want to get the
answer `meat` and `people`.


Answer: 
    import collections
    
    lines=[]
    with open('data1', 'r') as f:
        lines=list(map(lambda line:line.strip(), f.readlines()))
    
    d, flag=collections.defaultdict(list), False
    for line in lines:
        temp=list(map(lambda x:x.strip(), line.split()))
        d[temp[0]].append(temp[1:])
    print(d)
    

Here is the output:

    
    
    $ cat data1
    tiger eat meat
    tiger eat people
    rabbit eat carrot
    people can walk
    trees has root
    people has hand
    $ python3 a.py 
    defaultdict(<class 'list'>, {'rabbit': [['eat', 'carrot']], 'trees': [['has', 'root']], 'tiger': [['eat', 'meat'], ['eat', 'people']], 'people': [['can', 'walk'], ['has', 'hand']]})
    

**And if you want this structure:**

    
    
    $ python3 a.py 
    defaultdict(<class 'list'>, {'people': [{'can': 'walk'}, {'has': 'hand'}], 'tiger': [{'eat': 'meat'}, {'eat': 'people'}], 'trees': [{'has': 'root'}], 'rabbit': [{'eat': 'carrot'}]})
    

replace the 2nd last line in the script to:

    
    
    d[temp[0]].append({temp[1]:temp[2]})
    

