How to split strings inside a list by whitespace characters

前端 未结 4 1622
走了就别回头了
走了就别回头了 2020-11-30 11:57

So stdin returns a string of text into a list, and multiple lines of text are all list elements. How do you split them all into single words?

mylist = [\'thi         


        
4条回答
  •  盖世英雄少女心
    2020-11-30 12:24

    You could just do:

    words = str(list).split()
    

    So you turn the list into a string then split it by a space bar. Then you can remove the /n's by doing:

    words.replace("/n", "")
    

    Or if you want to do it in one line:

    words = str(str(str(list).split()).replace("/n", "")).split()
    

    Just saying this may not work in python 2

提交回复
热议问题