使用多个分隔符分割字符串
我有一个包含棋子坐标的字符串:
pieces = [Ka4Qb3Td7b4c4]
如何将字符串拆分为一个列表,并用数字分隔?
想要的输出:['Ka4','Qb3','Td7','b4','c4']
I have a string which contains coordinates of chess pieces:
pieces = [Ka4Qb3Td7b4c4]
How can i split the string into a list, separated by the numbers?
Wanted output : ['Ka4', 'Qb3', 'Td7', 'b4', 'c4']
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
闻起来像家庭作业,但很容易..
产量..
Smells like homework, but easy enough..
Yields..
这对我有用:
如果有两位数字分隔符,您可能需要调整正则表达式(我不是国际象棋爱好者...)
为了兴趣,我将其重新设计为建议的列表理解,并同意它更干净:
This works for me:
You may need to adjust the regex if there are 2 digit seperators (I'm not a chess guy...)
For interest sake, I reworked it as the suggested list comprehension and agree it's much cleaner: