Python adding dictionary values from separate script runs -
i have dictionary generated within script:
dict1 = {'a': 1, 'b': 2, 'c':3}
the script generate dictionary run many times on different files generate more dictionaries, each within own script:
dict2 = {'a': 5, 'b': 3, 'c':2} dict3 = {'a': 2, 'b': 1, 'c':0}
my plan add these file individually, add values same key (e.g. 1 entry 'a': 8) once file has been appended dictionaries.
is there way add values of dictionaries they're added file? or other way results in values being added each script completes?
edit: i'm new coding, please explain , if can. :)
i wanted add new generated dictionary values pre-existing file.
for example, dict 1 in file. did
with open(file.txt, "w") f: in dict.keys(): f.write(i + " " + str(dict[i]) + "\n")
to add dict 2, dict 3, etc file: took file.txt had dict1 , re-wrote dictionary
for line in f: values = line.split(sep) dict[values[0]] = int(values[1])
then added 2 dictionaries within program , re-wrote new dictionary out file.
probably not elegant answer, works!
Comments
Post a Comment