how to split list of sentences into another list(2D)?

I have a list named lists.

lists = [['Was the indus valley part of the maharashtra empire?',
  'Is there such a thing as golden age of indian culture?',
  'Is the vedic period the same as the golden age?']]

I want to convert all this sentences into different lists as shown below.

new_list = [['Was the indus valley part of the maharashtra empire?'],
  ['Is there such a thing as golden age of indian culture?'],
  ['Is the vedic period the same as the golden age?']]

how can I convert a 1D list into 2D list?

>Solution :

using list comprehension, you need to iterate through each sublist of lists and do [sentence] on each sentence while iterating over sublist.

result = [[sentence] for sublist in lists for sentence in sublist]

Leave a Reply