'How to convert 2d array to 1d array?
I have an array like this.
a = ["]['A few hours after the end of his last match in November 2013 the Prime Ministers Office announced the decision to award him the Bharat Ratna Indias highest civilian award.', 'Did a few hours after the end of his last match in November 2013 the Prime Ministers Office annount the decision to award him the Bharat Ratna Indias highest civilian award?'], ['A few hours after the end of his last match in November 2013 the Prime Ministers Office announced the decision to award him the Bharat Ratna Indias highest civilian award.', 'When after the end of his last match in November 2013 the Prime Ministers Office announced the decision to award him the Bharat Ratna Indias highest civilian award?']"]
I want to convert it into 1d list so that i am able to pick random question from that array.
after_conversion = [['A few hours after the end of his last match in November 2013 the Prime Ministers Office announced the decision to award him the Bharat Ratna Indias highest civilian award.', 'Did a few hours after the end of his last match in November 2013 the Prime Ministers Office annount the decision to award him the Bharat Ratna Indias highest civilian award?'], ['A few hours after the end of his last match in November 2013 the Prime Ministers Office announced the decision to award him the Bharat Ratna Indias highest civilian award.', 'When after the end of his last match in November 2013 the Prime Ministers Office announced the decision to award him the Bharat Ratna Indias highest civilian award?']]
when I check the type of the a ,it is showing a list.
from itertools import chain
flatten_list = list(chain.from_iterable(z))
flatten_list
output
[']',
'[',
"'",
'A',
' ',
'f',
'e',
'w',
' ',
'h',
'o',
'u',
'r',
's',
' ',
while using this code, getting an output like this. but i want output as given in after_conversion.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
