在删除字符串列表的特定值时遇到困难
因此,我要做的是删除字符串列表的一些特定值,我试图使用Regex to sucess,我想删除所有没有十进制房屋的值,我不能从一个某些索引,因为INT数字的位置有所不同。
的一个
['178', '34,79', '135925,82', '135926,82']
['102021', '191', '135067,69', '858,13', '859,13']
['176054330', '12', '506', '858,13', '0,00', '1,00']
这是我试图做这样的
re.compile(r'\d{1,5},\d{2}.*')
vend_values = list(filter(r.match, vend_name))
列表
['34,79', '135925,82', '135926,82']
['135067,69', '858,13', '859,13']
['858,13', '0,00', '1,00']
示例
So, what Iam triyng to do is remove some specific values of a list of strings, I've tried to use regex to no sucess, i want to remove all values that doesnt have a decimal house, i cant just get the numbers from a certain index because the position of the int number varies.
Here's an example of the list
['178', '34,79', '135925,82', '135926,82']
['102021', '191', '135067,69', '858,13', '859,13']
['176054330', '12', '506', '858,13', '0,00', '1,00']
I've tried to do something like this:
re.compile(r'\d{1,5},\d{2}.*')
vend_values = list(filter(r.match, vend_name))
To get this result:
['34,79', '135925,82', '135926,82']
['135067,69', '858,13', '859,13']
['858,13', '0,00', '1,00']
But with that it ends up removing some lines as well
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要使用像Regex这样的花哨的东西。在Python中,关键字中的
将为您完成工作。您也可以使用列表理解:
如果要将其转换为功能:
希望有帮助!
You don't need to use something as fancy as regex. In python, the
in
keyword will do the work for you. You can use list comprehension too:if you want to turn this into a function:
Hope that helps!