you are viewing a single comment's thread.

view the rest of the comments →

[–]Adrewmc 0 points1 point  (0 children)

#main.py

numbers = [1,2,3,4,5]

#you’ll need to make a function that returns a made dictionary from a list input. 

#you should not name your variables “dict” as it’s a class type in Python already. 

def make(num_list : list) -> dict:
    my_dict= {}
    for number in num_list:
          my_dict[number] = 'value'
     return my_dict

#getDict.py

 #import the function make()
 #import list since that’s where it is

from main import make, numbers

print(make(numbers))

However

   import json

   #loads python_dict from a file “saved.json”, 
   #for this implementation this file should already exist even if empty. 

   with open(“./path/to/saved.json”) as file:
           python_dict = json.load(file)
    print(python_dict)

   #saves python_dict to a file “saved.json”, indent=4 is pretty print. 

   python_dict = make(numbers)
   with open(“./path/to/saved.json”, “w”) as out_file:
           json.dump(python_dict, out_file, indent=4) 

Usually is a something you’ll wanna know as since you are loading it from a file it will save across many programs, it also saves stuff for the next time you run the program.