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

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -