如何在一行中写多行?我的输入是这样的:
HOXC11
HOXC11, HOX3H, MGC4906
human, Homo sapiens
HOXB6
HOXB6, HOX2, HU-2, HOX2B, Hox-2.2
human, Homo sapiens
HOXB13
HOXB13
human, Homo sapiens
PAX5
PAX5, BSAP
human, Homo sapiens
我需要像这样将其变成一行:
HOXC11 HOXC11, HOX3H, MGC4906 human, Homo sapiens
HOXB6 HOXB6, HOX2, HU-2, HOX2B, Hox-2.2 human, Homo sapiens
HOXB13 HOXB13 human, Homo sapiens
最佳答案
假设您的输入来自文件,我们称其为homosapiens.txt
,则可以从指定的输入转到所需的输出,如下所示:
with open('homosapiens.txt', 'r') as f:
for line in f:
if line == 'human, Homo sapiens':
print line # this will print and go to a newline
elif line:
print line, # the comma after line suppresses the newline
关于python - 如何在一行中写多行?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30135832/