python find substrings based on a delimiter

后端 未结 4 1911
离开以前
离开以前 2021-01-17 17:54

I am new to Python, so I might be missing something simple.

I am given an example:

 string = \"The , world , is , a , happy , place \" 
4条回答
  •  遇见更好的自我
    2021-01-17 18:13

    Simple thanks to the convenient string methods in Python:

    print "\n".join(token.strip() for token in string.split(","))
    

    Output:

    The
    world
    is
    a
    happy
    place
    

    By the way, the word string is a bad choice for variable name (there is an string module in Python).

提交回复
热议问题