【问题标题】:how to split list of sentences into another list(2D)?如何将句子列表拆分为另一个列表(2D)?
【发布时间】:2022-06-13 20:04:41
【问题描述】:

我有一个名为 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?']]

我想将所有这些句子转换成不同的列表,如下所示。

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

如何将一维列表转换为二维列表?

【问题讨论】:

    标签: python list


    【解决方案1】:

    使用列表理解

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

    【讨论】:

      猜你喜欢
      • 2015-12-13
      • 2018-08-13
      • 2010-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-11
      • 1970-01-01
      • 2011-03-28
      相关资源
      最近更新 更多