Skip to main content
deleted 35 characters in body
Source Link
William
  • 6.4k
  • 4
  • 35
  • 36

Since you're only looking at the keys value I'd use the iterkeysiteritems() method of the dictionary. It returns an interator rather than generating a full list like the items() method does.

results = [key for key, value in adictionary.iterkeysiteritems() if str(key).startswith('target') and value > 0]

Since you're only looking at the keys value I'd use the iterkeys() method of the dictionary. It returns an interator rather than generating a full list like the items() method does.

results = [key for key in adictionary.iterkeys() if str(key).startswith('target') and value > 0]

I'd use the iteritems() method of the dictionary. It returns an interator rather than generating a full list like the items() method does.

results = [key for key, value in adictionary.iteritems() if str(key).startswith('target') and value > 0]
Source Link
William
  • 6.4k
  • 4
  • 35
  • 36

Since you're only looking at the keys value I'd use the iterkeys() method of the dictionary. It returns an interator rather than generating a full list like the items() method does.

results = [key for key in adictionary.iterkeys() if str(key).startswith('target') and value > 0]