Skip to content

Instantly share code, notes, and snippets.

@woodphil
Created March 15, 2016 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save woodphil/de8b9d4fe14f3c82c625 to your computer and use it in GitHub Desktop.
Save woodphil/de8b9d4fe14f3c82c625 to your computer and use it in GitHub Desktop.
the power of dict comprehensions I
for i in list_thing:
temp = {}
data_obj = i.data
if data_obj:
data_within = data_obj.get('data1')
if data_within:
for data in data_within:
if data.get('field1') and data.get('field2):
temp[data] = helper.function(data_within[data].get('field1'), data_within[data].get('field2')
# reduced
for i in list_thing:
temp = {}
if i.data:
temp = {key: helper.function(value.get('field1'),value.get('field2')) for key, value in i.data.get('data1', {}).iteritems() if value.get('field1') and value.get('field2')}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment