<分区>
我有一个文件如下:
1:01
4:04
7:07
5:05
3:03
一般模式是<a number>:0<the same number before colon>
.我想删除冒号和冒号后的所有内容。这会产生。
1
4
7
5
3
在 bash 或 python 中实现此目的的简单方法是什么。
<分区>
我有一个文件如下:
1:01
4:04
7:07
5:05
3:03
一般模式是<a number>:0<the same number before colon>
.我想删除冒号和冒号后的所有内容。这会产生。
1
4
7
5
3
在 bash 或 python 中实现此目的的简单方法是什么。
最佳答案
将输入作为字符串列表,比如说
>>>input = ['1:01', '4:04', '7:07', '5:05', '3:03']
使用split
和列表推导式制作包含所需输出的列表
>>>output = [i.split(':')[0] for i in input]
现在你有了所需的输出:
>>>output
['1', '4', '7', '5', '3']
关于python - 删除冒号后的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41011854/