Hello, I have a text file with information on products, the first 3 lines can be seen below
CODBO, Call of Duty BlackOps, 120
SC2WL, Starcraft 2 WoL, 90
FONV0, Fallout New Vegas 100
CODBO is the ID, Call... is the name and 120 is the price.
What would the code be for a function that would turn that into a dictionary that looks similarly to this:
{'CODBO':('Call of Duty BlackOps',120), ...}
I have tried to think of a solution for 2 hours now and still dont have the faintest idea on how to do it. Any help is appreciated, thanks.
EDIT:
Thanks bvdet, i modified the code a bit and got it to work, here it is for reference.
CODBO, Call of Duty BlackOps, 120
SC2WL, Starcraft 2 WoL, 90
FONV0, Fallout New Vegas 100
CODBO is the ID, Call... is the name and 120 is the price.
What would the code be for a function that would turn that into a dictionary that looks similarly to this:
{'CODBO':('Call of Duty BlackOps',120), ...}
I have tried to think of a solution for 2 hours now and still dont have the faintest idea on how to do it. Any help is appreciated, thanks.
EDIT:
Thanks bvdet, i modified the code a bit and got it to work, here it is for reference.
Code:
def load_games(filename) : games = {} f = open(filename, 'U') s = '' for line in f: s = line sList = s.split(',') games[sList[0]] = sList[1].strip(), int(sList[2]) return games x = load_games('games.txt') print x
Comment