how can i assign a new value to a key of a dictionary thats already inside another dictionary without directly using the key's text(working with external jsons)code:
import json
brands = {1: 'lamtechfile.json'
, 2: 'celebratfile.json'}
lamtechitems = {1: 'type c to type c',
2: 'type c to usb'}
def viewproducts():
answer = int(input('What brand do you want to view?\n1. Lamtech\n2. Celebrat'))
with open(brands.get(answer), 'r') as file:
viewbrands = json.load(file)
for key, value in viewbrands.items():
print(key, ':', value)
def addsupply():
answer1 = int(input('From which brand do you want to chnange supply?\n1. Lamtech\n2. Celebrat'))
with open(brands.get(answer1), 'r') as file:
viewbrands = json.load(file)
for key, value in viewbrands.items():
print(key, ':', value)
items = []
for i in viewbrands:
items.append(i)
for x, y in enumerate(items, start=1):
print(x, y)
answer2 = input('Which item do you want to change the supply of?: ')
answer3 = input('What number do you want to set the supply to?')
viewbrands[lamtechitems.get(answer2)] = answer3
with open(brands.get(answer1), 'w') as file2:
json.dump(viewbrands, file2, indent=2)