Skip to main content
added 14 characters in body
Source Link

Convert usingConverting to a list without keysusing the keys method to makes it more readable:

list(newdict) 

and, when looping through dictionaries there is, there's no need for keys():

for key in newdict: print key 

unless you are modifying it within the loop which would require a list of keys created beforehand:

for key in list(newdict): del newdict[key] 

On Python 2 there is a marginal performance gain using keys().

Convert using list without keys method to makes it more readable:

list(newdict) 

and looping dictionaries there is no need for keys():

for key in newdict: print key 

unless you are modifying it within the loop which would require a list of keys created beforehand:

for key in list(newdict): del newdict[key] 

On Python 2 there is a marginal performance gain using keys().

Converting to a list without using the keys method makes it more readable:

list(newdict) 

and, when looping through dictionaries, there's no need for keys():

for key in newdict: print key 

unless you are modifying it within the loop which would require a list of keys created beforehand:

for key in list(newdict): del newdict[key] 

On Python 2 there is a marginal performance gain using keys().

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Convert using list without keys method to makes it more readable:

list(newdict) 

and looping dictionaries there is no need for keys():

for key in newdict: print key 

unless you are modifying it within the loop which would require a list of keys created beforehand:

for key in list(newdict): del newdict[key] 

On Python 2 there is a marginal performance gain using keys()keys().

Convert using list without keys method to makes it more readable:

list(newdict) 

and looping dictionaries there is no need for keys():

for key in newdict: print key 

unless you are modifying it within the loop which would require a list of keys created beforehand:

for key in list(newdict): del newdict[key] 

On Python 2 there is a marginal performance gain using keys().

Convert using list without keys method to makes it more readable:

list(newdict) 

and looping dictionaries there is no need for keys():

for key in newdict: print key 

unless you are modifying it within the loop which would require a list of keys created beforehand:

for key in list(newdict): del newdict[key] 

On Python 2 there is a marginal performance gain using keys().

add link to dict keys performance and tidyup text
Source Link
Cas
  • 7k
  • 3
  • 41
  • 37

Simply convert toConvert using list without requiring the keys method and itto makes it more readable:

list(newdict) 

and with for loops on dictslooping dictionaries there is no need for keys():

for key in newdict: print key 

unless you are modifying newdictit within the loop which doeswould require a list of keys created beforehand:

for key in list(newdict): del newdict[key] 

On Python 2 there is a marginal performance gain using keys().

Simply convert to list without requiring the keys method and it makes it more readable:

list(newdict) 

and with for loops on dicts there is no need for keys():

for key in newdict: print key 

unless you are modifying newdict within the loop which does require a list of keys:

for key in list(newdict): del newdict[key] 

Convert using list without keys method to makes it more readable:

list(newdict) 

and looping dictionaries there is no need for keys():

for key in newdict: print key 

unless you are modifying it within the loop which would require a list of keys created beforehand:

for key in list(newdict): del newdict[key] 

On Python 2 there is a marginal performance gain using keys().

Source Link
Cas
  • 7k
  • 3
  • 41
  • 37
Loading