How do I save and reload my Python dictionary?

Asked 2 years ago, Updated 2 years ago, 31 views

For example, dict ={} dict[0930] = ['s', 'a', 'g']

dict = {0930 : ['s', 'a', 'g']} It's an index

Save this dict value and

next time dict[1000] = ['a', 'b', 'k'] When you enter

dict = {0930 : ['s', 'a', 'g'], 1000 : ['a', 'b', 'k']} What is the way to add it as?<

python

2022-09-21 20:27

2 Answers

Dictionary is an item addition if the key is not duplicated.


2022-09-21 20:27

Just do as you say.

But don't use dict as a variable name. The class name of the dictionary data type.

>>> d = {}
>>> d['0930'] = ['s','a','g']
>>> d
{'0930': ['s', 'a', 'g']}
>>> d['1000'] = ['a','b','k']
>>> d
{'0930': ['s', 'a', 'g'], '1000': ['a', 'b', 'k']}


2022-09-21 20:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.