Answers for "python update keys in dict with ma[p"

5

python change a key in a dictionary

# Basic syntax:
# Approach 1:
dictionary[new_key] = dictionary[old_key]
del dictionary[old_key]

# Approach 2:
dictionary[new_key] = dictionary.pop(old_key)
Posted by: Guest on April-26-2021
2

how to set a key of dict in python

# declaring dict
dictionary={'Hello':3,'World!':4}
# creating function
def dict_add(obj,key,value):
  obj[key]=value
  reutrn obj
# using the functiom
dict_add(dictionary,'Python',10)
print (dictionary) # output --> { 'Hello':3 ,'World!':4 , 'Python':10 }
Posted by: Guest on September-22-2020

Python Answers by Framework

Browse Popular Code Answers by Language