Python Forum
What is the best way to add entries from 1 dictionary to another?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is the best way to add entries from 1 dictionary to another?
#2
With a list, you can append a new value into the list.

>>> l = [1, 2]
>>> l.append(3)
>>> l
[1, 2, 3]
With a dict, you can add a key/value pair that wasn't there before, or you can update it with another dict, and that either add or changes the values of any matching keys.

>>> d = {'a': 1, 'b': 2}
>>> d['c'] = 3
>>> d.update({'d': 4})
>>> d
{'a': 1, 'b': 2, 'c': 3, 'd': 4}
Reply


Messages In This Thread
RE: What is the best way to add entries from 1 dictionary to another? - by bowlofred - Oct-20-2020, 07:57 AM

Forum Jump:

User Panel Messages

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