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' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -