python字符串使用小括号_Python用括号分隔字符串

你的问题没有很好地解决。

你对规则的描述是In other words if it is one word seperated by a space then split it

from the next word, if it is in parentheses then split the whole group

of words in the parentheses and remove them. Same goes for the commas.

我猜你用逗号是指反逗号==引号。

然后用这个strs = "Hello (Test1 test2) (Hello1 hello2) other_stuff"

你应该明白["Hello (Test1 test2) (Hello1 hello2) other_stuff"]

因为所有的东西都被反逗号包围。最有可能的是,您不需要关心最大的倒逗号。

我提议这样,尽管一个丑陋的机器人import re, itertools

strs = raw_input("enter a string list ")

print [ y for y in list(itertools.chain(*[re.split(r'\"(.*)\"', x)

for x in re.split(r'\((.*)\)', strs)]))

if y <> '']

获取>>>

enter a string list here there (x y ) thereagain "there there"

['here there ', 'x y ', ' thereagain ', 'there there']

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值