[英]remove everything except lines with % and remove the %
例子:
1
Yuumi
78.57%
2075
1956
0.64
62.8
Thresh
77.59%
1079
917
0.83
19.3
Braum
76.00%
1868
1315
1.44
38.0
我希望它是:
78.57
77.59
76.00
(带有 % 的数字)
尝试在论坛中查找并使用文件和内容中的 readlines,但我是初学者,无法在 python 中使用它,在此先感谢
with open('path/to/the/file') as fd:
for line in fd:
if '%' in line:
print(line.strip().replace('%', ''))
或者您可以在 shell 中执行此操作:
grep "%" filename | sed 's/%//g' >newfile
假设您已将所有输入读入列表。 你可以试试这个。
inp = ['1', 'Yuumi', '78.59%', ...]
out = [float(a.remove('%')) for a in inp if '%' in a]
如果您这样做,您可以将文件中的所有输入放入列表中
with open('my_file.txt') as file:
inp = file.read.splitlines()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.