splitting a list of sentences into separate words in a list

后端 未结 4 393
失恋的感觉
失恋的感觉 2021-01-16 18:33

I have a list which consists of lines as

lines =  [\'The query complexity of estimating weighted averages.\',
     \'New bounds for the query complexity of a         


        
4条回答
  •  不知归路
    2021-01-16 19:11

    You can use a list comprehension:

    >>> lines =  [
    ...     'The query complexity of estimating weighted averages.',
    ...     'New bounds for the query complexity of an algorithm that learns',
    ... ]
    >>> [word for line in lines for word in line.split()]
    ['The', 'query', 'complexity', 'of', 'estimating', 'weighted','averages.', 'New', 'bounds', 'for', 'the', 'query', 'complexity', 'of', 'an', 'algorithm', 'that', 'learns']
    

提交回复
热议问题