-1

Hello, I'm still very new to python, and I'm tyring to figure out how I would parse data from an input file.
Here is what the input file would look like.

B 128.9 hello 2918.1 hi 2938.2 world
H 12.2 India 218.6 Lost 29.9 Place
C 28.3 Watch 28.4 Found 293.9 Palace
...
...
...

I'm trying to seperate the first capitalized letter into a command variable, and the 128.9, "hello" into a dictionary together. Then do the same for 2918.1 and "hi" into the next dictionary level. so on and so on. until I find the next command and take that data near it for the other function. How would I be able to do this? I just can't figure out how to seperate them all. Thanks!

Edited by Ravic85

3
Contributors
2
Replies
30
Views
4 Years
Discussion Span
Last Post by phorce
0

Can you provide the expected output?
What is a command variable?
What is a dictionary level?
What I understand is that the first two lines should be stored as:

data={"B":(
    (128.9,"hello"),
    (1918.1,"hi"),
    (2938.2,"world"),
    ),
      "H":(
    (12.2,"India"),
    (218.6,"Lost"),
    (29.9,"Place"),
    )
}

Edited by slate: spelling

0

Did you not ask this in C++? :S Choose which language you're going to work in.. Better still, build it in one language and make an interface in different languages? Don't re-invent code in multiple languages, unless you absolutely have to.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.