Py学习  »  Python

如何将以下Python字符串拆分为字符串列表?

Big geez • 6 年前 • 1907 次点击  

我有一根绳子 'Predicate(big,small)'

['Predicate','(','big',',','small',')']

名字可以是任何东西,元素之间也可以有空格,比如so(我需要从列表中去掉空格), Predicate (big, small)

到目前为止我已经试过了,但这显然不是我想要的结果

>>> str1 = 'Predicate(big,small)'
>>> list(map(str,str1))

输出:

['P', 'r', 'e', 'd', 'i', 'c', 'a', 't', 'e', '(', 'b', 'i', 'g', ',', 's', 'm', 'a', 'l', 'l', ')']
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/55863
文章 [ 2 ]  |  最新文章 6 年前