Created
March 15, 2016 21:15
-
-
Save woodphil/de8b9d4fe14f3c82c625 to your computer and use it in GitHub Desktop.
the power of dict comprehensions I
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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