I have a list like this. containing question and its answer.
list=[['It has been noted that in __________________ urban cities quickly expanded rather than the slow evolution of urbanism in the northwest.',
'Gujarat'],
['These traditions and cultures include Anarta Tradition c. 39501900 BC Padri Ware 36002000 BC PrePrabhas Assemblage 32002600 BC Pre Urban Harappan Sindh __________________ Pottery Burial Pottery 30002600 BC Black and Red Ware 3950900 BC Reserved Slip Ware 39501900 BC Micaceous Red Ware 26001600 BC.',
'Type'],
['Later in the 18th century Gujarat came under control of the __________________ Empire who dominated the politics of India.',
'Maratha']]
I want to convert in into given form.
output =[{'question': 'It has been noted that in __________________ urban cities quickly expanded rather than the slow evolution of urbanism in the northwest.','answer':'Gujarat'}, {'question': 'These traditions and cultures include Anarta Tradition c. 39501900 BC Padri Ware 36002000 BC PrePrabhas Assemblage 32002600 BC Pre Urban Harappan Sindh __________________ Pottery Burial Pottery 30002600 BC Black and Red Ware 3950900 BC Reserved Slip Ware 39501900 BC Micaceous Red Ware 26001600 BC.','answer':'Type'}, {'question': 'Later in the 18th century Gujarat came under control of the __________________ Empire who dominated the politics of India.','answer':'Maratha'}
Is it possible ? If yes , then how ?
A list comprehension will suffice:
[{'question': q, 'answer': a} for q, a in list]
This outputs:
[{'question': 'It has been noted that in __________________ urban cities '
'quickly expanded rather than the slow evolution of urbanism in '
'the northwest.',
'answer': 'Gujarat'},
{'question': 'These traditions and cultures include Anarta Tradition c. '
'39501900 BC Padri Ware 36002000 BC PrePrabhas Assemblage '
'32002600 BC Pre Urban Harappan Sindh __________________ Pottery '
'Burial Pottery 30002600 BC Black and Red Ware 3950900 BC '
'Reserved Slip Ware 39501900 BC Micaceous Red Ware 26001600 BC.',
'answer': 'Type'},
{'question': 'Later in the 18th century Gujarat came under control of the '
'__________________ Empire who dominated the politics of India.',
'answer': 'Maratha'}]
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments