User Profile

Collapse

Profile Sidebar

Collapse
ChaoticBlack
ChaoticBlack
Last Activity: May 17 '11, 08:18 AM
Joined: Apr 5 '11
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • So far I can create a list with the games (code below), how can I convert it to a dictionary in the style {'CODBO':('Call of Duty BlackOps',120), ...}?
    Code:
    def load_games(filename) :
        games = {}
        f = open(filename, 'U')
        s = ''
        for line in f:
            s += line
        sList = s.split(',')
        return sList
    
    x = load_games('games.txt')
    print x
    Has the output
    Code:
    >>>
    ...
    See more | Go to post

    Leave a comment:


  • Yeh I know most of the basics with dictionaries and files, that code helps a lot, Ill try to include it in a for loop and iterate over every line. Ill post the code soon if it doesn't work. Thanks
    See more | Go to post
    Last edited by ChaoticBlack; Apr 6 '11, 01:55 AM.

    Leave a comment:


  • Convert file with information into dictionary

    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...
    See more | Go to post
No activity results to display
Show More
Working...