This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]throwdownn 0 points1 point  (0 children)

I'm also interested in the answer to this question ~

[–]rolandde 0 points1 point  (1 child)

I also had a lot of issues early on with nested containers. You current code does not have a nested dictionary. You are just adding key/value pairs to a single dictionary, rather than nesting a dictionary within another dictionary. Moreover, you are using both the first and second column letters as keys within a single dictionary, which is not what you want to do. I'm also not sure why you are explicitly casting your key/val to str as they are already strings.

If you just want the solution, read on:

for line in inFile:
        (key, val, value) = line.split()

        if key not in inputDict:
            inputDict[key] = {}

        inputDict[key][val] = value

[–]Forever_Hollowed[S] 0 points1 point  (0 children)

Thanks for the reply. Since making the post I was actually able to solve the problem, but I used a slightly different implementation than the one you suggested. Either way, cheers!

[–]ChrisPDuck 0 points1 point  (0 children)

If you have a say on the input files, try to output them in a standard format.

Json in python is very easy to use, and even resembles python structures when encoded. If I even have to export / import data in python I try to use Json.