Python Forum
Move a key:value in a dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Move a key:value in a dictionary
#4
Python 3.9,as merge together with batman dict first it will keep order,not that it matter to much as mention.
>>> d = batman | super_hero_names
>>> d
{'Batman': 'Bruce', 'Superman': 'Clark Kent', 'Spiderman': 'Peter Parker'}
>>> d.update(Batman = "Bruce Wayne")
>>> d
{'Batman': 'Bruce Wayne', 'Superman': 'Clark Kent', 'Spiderman': 'Peter Parker'}
For Python 3.8 d = {**batman, **super_hero_names}.
nilamo likes this post
Reply


Messages In This Thread
Move a key:value in a dictionary - by dgrunwal - Feb-23-2021, 09:17 PM
RE: Move a key:value in a dictionary - by buran - Feb-23-2021, 09:26 PM
RE: Move a key:value in a dictionary - by snippsat - Feb-23-2021, 10:18 PM
RE: Move a key:value in a dictionary - by dgrunwal - Feb-24-2021, 02:43 PM

Forum Jump:

User Panel Messages

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