How to remove element from a dictionary and give his values to other key with Python

2 Answers

0 votes
dic = {'a':13, 'b':96, 'c':8, 'd':24, 'e':36, 'f':17, 'g':6, 'h':25}
 
dic['b'] = dic.pop('h')
 
print(dic)
 
 
 
 
'''
run:
 
{'a': 13, 'b': 25, 'c': 8, 'd': 24, 'e': 36, 'f': 17, 'g': 6}

'''

 



answered Mar 15, 2023 by avibootz
0 votes
dic = {'a':13, 'b':96, 'c':8, 'd':24, 'e':36, 'f':17, 'g':6, 'h':25}
 
dic['b'] = dic['h']

del dic['h']

print(dic)
 
 
 
 
'''
run:
 
{'a': 13, 'b': 25, 'c': 8, 'd': 24, 'e': 36, 'f': 17, 'g': 6}

'''

 



answered Mar 15, 2023 by avibootz
...