python templist什么意思_在python里的list问题求教!!!!!

在python里,如何用list的方法将一个string按给定的特殊符号断开,将断开的元素存放为一个list。我给出具体题目,我在国外学习,所以题目是英文的,大家见谅。defsplit_on_separators...

在python里,如何用list的方法将一个string按给定的特殊符号断开,将断开的元素存放为一个list。我给出具体题目,我在国外学习,所以题目是英文的,大家见谅。

def split_on_separators(original, separators):

''' Return a list of non-empty, non-blank strings from the original string

determined by splitting the string on any of the separators.

separators is a string of single-character separators.'''

#To do. complete this function to meet the specification

# you are not required to keep the two lines below but you may find

# them helpful. (Hint)

result = [original]

return result

大意:从原来的string中return一个非空的string的数列(list),在list中的string是由原string被用户输入的特定分隔符分开的。这就是大体意思,翻译水平烂,但是自己看的懂,没有调整语序,大家见谅

我附上一个例子split_on_separators("Hooray! Finally, we're done.",'!,') should return ['Hooray', ' Finally', " we're done."]

以下三楼我全部测试过了,如果我的separators是‘!,’就是有2个符号连在一起并且用但引号扩出,那么你们的方法最后return的时候就不对了,要像我给的例子一样

展开

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值