Working with dictionaries and keys help please!
MRAB
python at mrabarnett.plus.com
Wed May 31 20:58:14 EDT 2017
On 2017-06-01 01:29, David D wrote:
> I have a dictionary with a 10 people, the key being a number (0-10) and the value being the people's name. I am in the processing of Insert, Adding and deleting from the dictionary. All seems well until I delete a person and add a new one. The numbers (keys) do not change and so I am getting an non-sequential set of numbers for the keys. Is there a way of performing this where the key will update so that is continues to work sequentially? Here is what I mean
>
> Print dictionary
> {0 John, 1 David, 2 Phil, 3 Bob}
>
> remove 1 David
> {0 John, 2 Phil, 3 Bob}
>
> How can I get it so that the VALUE will reset and it will look like this after both adding or deleting?
>
> {0 John, 1 Phil, 2 Bob}
>
Why are you using a dictionary instead of a list?
More information about the Python-list
mailing list