I’ve just read in a file that is something like:
name: john, jane
car: db9, m5
food: pizza, lasagne
Each of these rows (names, car, food) are in order of who owns what. Therefore John owns the car ‘DB9’ and his favourite food is ‘Pizza’. Likewise with Jane, her car is an ‘M5’ and her favourite food is ‘Lasagne’.
I effectively have:
>>> names['Name']="John"
>>> namesL.append(name)
>>> names['Name']="Jane"
>>> namesL.append(name)
>>> car['Car']="DB9"
>>> cars.append(car)
>>> car['Car']="M5"
>>> cars.append(car)
>>> food['Food']="Pizza"
>>> foodL.append(food)
>>> food['Food']="Lasagne"
>>> foodL.append(food)
>>>ultimateList.append(foodL)
...
However I want it so that each of these things are in their own dictionary. So something like this:
>>>PersonalDict
{'Name': 'John', 'Car': 'DB9', 'Food': 'Pizza'}
I’ve been staring at it for a while and can’t work out how I should approach this. Can anyone offer some ideas or shall I just do this some other way?
Looks like you want something like:
That doesn’t do exactly what you specify (the capitalization of the
BinDB9seems totally weird for example — how would the code know to capitalize that particular second letter and not any other second letter?!) but it seems pretty close.