python - Python3 change key type of nested dict from string to integer -


i have dict structure

      players =  {xxx:                   {'name'         : "admin"},                   yyy:                  {'name'         : "user"}                 } 

xxx , yyy meaning keys string. want them integer. how can convert keys integer please?

assuming strings xxx , yyy contain valid integer representations, can use following construct dict key values converted integers:

players2 = {int(k) : v k, v in players.items()} 

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -