tl;dr
[str for dic in data
for data_dict in dic['data']
for writing_sub_list in data_dict['writing']
for str in writing_sub_list]
Just go slow and do one layer at a time. Then refactor your code to make it smaller.
data = [{'class': '?',
'data': [{'chunk': 1,
'writing': [['this is exciting'], ['you are good']]}],
'uid': 'test_subject145'},
{'class': '?',
'data': [{'chunk': 2,
'writing': [['he died'], ['go ahead']]}],
'uid': 'test_subject166'}]
for d in data:
print(d)
# {'class': '?', 'uid': 'test_subject145', 'data': [{'writing': [['this is exciting'], ['you are good']], 'chunk': 1}]}
# {'class': '?', 'uid': 'test_subject166', 'data': [{'writing': [['he died'], ['go ahead']], 'chunk': 2}]}
for d in data:
data_list = d['data']
print(data_list)
# [{'writing': [['this is exciting'], ['you are good']], 'chunk': 1}]
# [{'writing': [['he died'], ['go ahead']], 'chunk': 2}]
for d in data:
data_list = d['data']
for d2 in data_list:
print(d2)
# {'writing': [['this is exciting'], ['you are good']], 'chunk': 1}
# {'writing': [['he died'], ['go ahead']], 'chunk': 2}
for d in data:
data_list = d['data']
for d2 in data_list:
writing_list = d2['writing']
print(writing_list)
# [['this is exciting'], ['you are good']]
# [['he died'], ['go ahead']]
for d in data:
data_list = d['data']
for d2 in data_list:
writing_list = d2['writing']
for writing_sub_list in writing_list:
print(writing_sub_list)
# ['this is exciting']
# ['you are good']
# ['he died']
# ['go ahead']
for d in data:
data_list = d['data']
for d2 in data_list:
writing_list = d2['writing']
for writing_sub_list in writing_list:
for str in writing_sub_list:
print(str)
# this is exciting
# you are good
# he died
# go ahead
Then to convert to something smaller (but hard to read), rewrite the above code like this. It should be easy to see how to go from one to the other:
strings = [str for d in data for d2 in d['data'] for wsl in d2['writing'] for str in wsl]
# ['this is exciting', 'you are good', 'he died', 'go ahead']
Then, make it pretty with better names like Willem's answer:
[str for dic in data
for data_dict in dic['data']
for writing_sub_list in data_dict['writing']
for str in writing_sub_list]