help on Implementing a list of dicts with no data pattern

Dave Angel davea at davea.name
Thu May 9 10:50:45 EDT 2013


On 05/09/2013 10:33 AM, rlelis wrote:
> I apologize once again.
> Is my first post here and i'm getting used to the group as long as i get the feedback of my errors by you guys.
> I'm using Python 2.7.3 with no dependencies, i'm simply using the standard
> library.
> Here is the "big picture" of the scenario(i have added it in the pastebin link too)
>
> FILE OUTPUT DESIRED:
> aging:
> aging  |total         |age
> aging  |0             |100
> aging  |2             |115
> aging  |3             |1
> aging  |4             |10
>
> highway:
> highway       | lanes         |       state   |       limit(mph)
> highway       |       4       |       disable |       25
> highway       |       2       |       disable |       245
> highway       |       3       |       disable |       125
> highway       |       2       |       enable  |       255
> highway       |       3       |       disable |       212
> highway       |       8       |       disable |       78
>
> FILE INPUT EXCERPT EXAMPLE:
> aging 0 100
> aging 2 115
> aging 3 1
> highway 4 disable 25
> highway 2 disable 245
> highway 0 enable 125
>
> Meanwhile i have change the code a little bit and achieve a output closer to what i want:

You're still missing the file read code.  My earlier assumption that it 
was a simple readlines() was bogus, or the line:
    if "aging" in file-content:

would never work.

Perhaps you have something like:

infile = open("xxxx","r")
file_content = [line.split() for line in infile]

if you confirm it, I'll try to go through the code again, trying to make 
sense of it.



-- 
DaveA



More information about the Python-list mailing list