Python Forum
Independent Secondary index for dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Independent Secondary index for dictionary
#10
here is what the JSON file looks like (Griboullis solution)
Output:
{"xyz corp": {"company_id": "12345", "CompanyDetail": {"Addr1": "45 Indianola Ave.", "City": "Columbus", "State": "Ohio"}}, "12345": {"company_id": "12345", "CompanyDetail": {"Addr1": "45 Indianola Ave.", "City": "Columbus", "State": "Ohio"}}}
code:
import BusinessPaths
import json

bpath = BusinessPaths.BusinessPaths()

company = {
    'xyz corp': {
        'company_id': '12345',
        'CompanyDetail': {
            'Addr1': '45 Indianola Ave.',
            'City': 'Columbus',
            'State': 'Ohio'
        } 
    }
}

company['12345'] = company['xyz corp']

json_file = bpath.tmppath / 'comp.json'
with json_file.open('w') as fp:
    json.dump(company, fp)
print(company)
Output:
{'xyz corp': {'company_id': '12345', 'CompanyDetail': {'Addr1': '45 Indianola Ave.', 'City': 'Columbus', 'State': 'Ohio'}}, '12345': {'company_id': '12345', 'CompanyDetail': {'Addr1': '45Indianola Ave.', 'City': 'Columbus', 'State': 'Ohio'}}}
sure looks like a copy of data, maybe not in the dictionary, but when saved?
Reply


Messages In This Thread
RE: Independent Secondary index for dictionary - by Larz60+ - Dec-20-2018, 07:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiple user defined plots with secondary axes using for loop maltp 1 1,581 Apr-30-2022, 10:19 AM
Last Post: maltp
  Making a plot with secondary y-axis bigger snkm 0 1,174 Feb-10-2022, 09:40 AM
Last Post: snkm
  Loop independent of excecution time of a script Forelli 8 3,959 Feb-02-2020, 10:49 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020