Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading