Python 删除列表中的列表

Python 删除列表中的列表,python,nltk,Python,Nltk,我正在使用NLTK库。我有一个名为chunks的列表,我想在该列表中添加单词,所以我正在做: def np_chunk(tree): chunks = [] for rama in tree: if rama.label() == "NP": chunks.append(rama.leaves()) print(chunks) 但这就是我得到的: [[他自己]] 这是列表中的一个列表。如何合并它们并使其仅成为一个列表?我想阻止ram

我正在使用NLTK库。我有一个名为
chunks
的列表,我想在该列表中添加单词,所以我正在做:

def np_chunk(tree):
  chunks = []
  for rama in tree:
      if rama.label() == "NP":
         chunks.append(rama.leaves())
  print(chunks)
但这就是我得到的:
[[他自己]]
这是列表中的一个列表。如何合并它们并使其仅成为一个列表?我想阻止
rama.leaves()
返回列表,直接从
块中删除内部列表

有什么想法吗?

您可以使用
list.extend
rama.leaves()
返回的所有元素添加到
块中

def np_chunk(tree):
  chunks = []
  for rama in tree:
      if rama.label() == "NP":
         chunks.extend(rama.leaves())
  print(chunks)
您还可以使用
列表
添加:

chunks += rama.leaves()