Python - how to separate paragraphs from text?

后端 未结 5 1046
花落未央
花落未央 2020-12-21 13:05

I need to separate texts into paragraphs and be able to work with each of them. How can I do that? Between every 2 paragraphs can be at least 1 empty line. Like this:

<
5条回答
  •  攒了一身酷
    2020-12-21 13:33

    I usually split then filter out the '' and strip. ;)

    a =\
    '''
    Hello world,
      this is an example.
    
    Let´s program something.
    
    
    Creating  new  program.
    
    
    '''
    
    data = [content.strip() for content in a.splitlines() if content]
    
    print(data)
    

提交回复
热议问题