I
I
Ilya1992018-06-26 18:56:58
Python
Ilya199, 2018-06-26 18:56:58

How to change the key in a dictionary?

I am reading a book on python, in a practical task you need to write an address book, you can write, delete, add, search for contact information in it.
I wrote everything perfectly, except for changing contact details
In general, all contact details are written to the dictionary, and when the user selects the option to change these contact details, an input is displayed where you need to enter the person's name, then a condition for whether there is such a person and if there is one , a choice is given: change the name/number.
I started with the name, registered the input, when the user enters a new name, the program cycles through the dictionary.
After reading on Google, I found out that you can try to delete the old key along with the value (if it is possible not to delete the value, write) and enter the key that the user wrote, that is, the new name of the person. The problem is in the value of the key, how to copy/save it, then add it back to that key with a new person's name
Simply put, I need to somehow leave the value with the new key
Since I started with a name, I think it will be easier with a number, because I already know how to do it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Pugachev, 2018-06-26
@Ilya199

The problem is in the value of the key, how to copy / save it, then add it again to this key with a new person name

The topic "variables" has already been covered in the book?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question