0

I have the following Python code.

import json
temp_string = ""

with open("data_elements.json") as json_file:  
    data = json.load(json_file)
    for p in data:
        this_ldraw = p["ldraw"]
        this_lgeo = p["lgeo"]
        this_ldraw = this_ldraw.strip(".dat")
        this_lgeo = this_lgeo.strip("lg_")
        this_lgeo = this_lgeo.strip(".inc")
        print(this_ldraw + "\t" + this_lgeo)

I have some JSON:

[
{"ldraw":"003238a.dat","lgeo":"lg_003238a.inc","slope":"0","anton":"0","lutz":"0","owen":"0","darats":"0"},
{"ldraw":"003238b.dat","lgeo":"lg_003238b.inc","slope":"0","anton":"0","lutz":"0","owen":"0","darats":"0"},
{"ldraw":"003238c.dat","lgeo":"lg_003238c.inc","slope":"0","anton":"0","lutz":"0","owen":"0","darats":"0"},
{"ldraw":"003238d.dat","lgeo":"lg_003238d.inc","slope":"0","anton":"0","lutz":"0","owen":"0","darats":"0"},
{"ldraw":"003238e.dat","lgeo":"lg_003238e.inc","slope":"0","anton":"0","lutz":"0","owen":"0","darats":"0"},
{"ldraw":"003238f.dat","lgeo":"lg_003238f.inc","slope":"0","anton":"0","lutz":"0","owen":"0","darats":"0"},
{"ldraw":"003238g.dat","lgeo":"lg_003238g.inc","slope":"0","anton":"0","lutz":"0","owen":"0","darats":"0"},
{"ldraw":"003238h.dat","lgeo":"lg_003238h.inc","slope":"0","anton":"0","lutz":"0","owen":"0","darats":"0"},
{"ldraw":"003238i.dat","lgeo":"lg_003238i.inc","slope":"0","anton":"0","lutz":"0","owen":"0","darats":"0"},
{"ldraw":"003238j.dat","lgeo":"lg_003238j.inc","slope":"0","anton":"0","lutz":"0","owen":"0","darats":"0"}
]

The Python script is supposed to process the "ldraw" column and the "lgeo" column such that the result of the processing is two identical columns in the output. However, the output is not in the correct order.

The output looks like this:

003238  003238a
003238b 003238b
003238c 003238
003238  003238d
003238e 003238e
003238f 003238f
003238g 003238g
003238h 003238h
003238i 003238
003238j 003238j

What am I doing wrong? Thanks.

posfan12
  • 2,541
  • 8
  • 35
  • 57

0 Answers0