Working with dictionaries and keys help please!

Gregory Ewing greg.ewing at canterbury.ac.nz
Fri Jun 2 04:06:59 EDT 2017


> On Thu, 1 Jun 2017 10:29 am, David D wrote:
> 
>> Is there a way of performing this
>> where the key will update so that is continues to work sequentially?

It sounds like you don't want a dictionary at all, you want a list.
You can use the index() method to find the current "key" of an entry.

 >>> people = ["John", "David", "Phil", "Bob"]
 >>> people.index("Phil")
2
 >>> people.remove("David")
 >>> people.index("Phil")
1

-- 
Greg



More information about the Python-list mailing list