如果使用Python 3.7中的条件,如何仅使用单个if条件而不是两个来重写下面的代码?
with open('demo.csv', 'r') as f, open("Result_csv.csv", 'w+') as out:
for line in f:
if '/tcp' in line:
print(line)
out.write(line)
if '/udp' in line:
print(line)
out.write(line)
Run Code Online (Sandbox Code Playgroud)