从具有多个字符串元素的数组中提取数字
一个阵列有4个元素。我只想打印出数千个。
my_array = ['STK72184 4/28/2022 50 from Exchange Balance, 50 from Earning Balance & 10 from Bonus 5000 Regular 10/20/2023 Approved 4/28/2022',
'STK725721 4/27/2022 50 from Exchange Balance, 40 from Earning Balance & 10 from Bonus Balance 5000 Regular 10/19/2023 Approved 4/27/2022',
'STK725721 4/27/2022 50 from Exchange Balance, 40 from Earning Balance & 10 from Bonus Balance 15000 Regular 10/19/2023 Approved 4/27/2022',
'STK722222 4/26/2022 50 from Exchange Balance, 40 from Earning Balance & 10 from Bonus Balance 10000 Regular 10/18/2023 Approved 4/26/2022']
预期输出为:
[‘5000’, ‘5000’, ‘15000’, ‘10000’]
An array has 4 elements. I want only the the thousands to printed out.
my_array = ['STK72184 4/28/2022 50 from Exchange Balance, 50 from Earning Balance & 10 from Bonus 5000 Regular 10/20/2023 Approved 4/28/2022',
'STK725721 4/27/2022 50 from Exchange Balance, 40 from Earning Balance & 10 from Bonus Balance 5000 Regular 10/19/2023 Approved 4/27/2022',
'STK725721 4/27/2022 50 from Exchange Balance, 40 from Earning Balance & 10 from Bonus Balance 15000 Regular 10/19/2023 Approved 4/27/2022',
'STK722222 4/26/2022 50 from Exchange Balance, 40 from Earning Balance & 10 from Bonus Balance 10000 Regular 10/18/2023 Approved 4/26/2022']
Expected output is:
[‘5000’, ‘5000’, ‘15000’, ‘10000’]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
re.search
,将第一匹匹配到1个或更多位数的模式,然后是3个零。Use
re.search
, which extract the first match to the pattern of 1 or more digit, followed by 3 zeros.尝试以下操作:
Try this:
您可以映射一个功能,该函数将首先分配为字符串并在所需的数组中获取项目,在这种情况下:
you could map a function that, splits the first the string and taking the item in the array that you want, in this case: