for*_*unk 1 python printing list
我有一个检查要完成,如果检查满足,我想要打印结果.以下是代码:
import string
import codecs
import sys
y=sys.argv[1]
list_1=[]
f=1.0
x=0.05
write_in = open ("new_file.txt", "w")
write_in_1 = open ("new_file_1.txt", "w")
ligand_file=open( y, "r" ) #Open the receptor.txt file
ligand_lines=ligand_file.readlines() # Read all the lines into the array
ligand_lines=map( string.strip, ligand_lines ) #Remove the newline character from all the pdb file names
ligand_file.close()
ligand_file=open( "unique_count_c_from_ac.txt", "r" ) #Open the receptor.txt file
ligand_lines_1=ligand_file.readlines() # Read all the lines into the array
ligand_lines_1=map( string.strip, ligand_lines_1 ) #Remove the newline character from all the pdb file names
ligand_file.close()
s=[]
for i in ligand_lines:
for j in ligand_lines_1:
j = j.split()
if i == j[1]:
print j
Run Code Online (Sandbox Code Playgroud)
上面的代码工作得很好,但是当我打印j时,它打印得像['351','342'],但我希望得到351 342(中间有一个空格).因为它更像是一个python问题,所以我没有包含输入文件(基本上它们只是数字).
谁能帮我?
干杯,
Chavanak
要将字符串列表转换为单个字符串,并在列表的项目之间使用空格,请使用' '.join(seq).
>>> ' '.join(['1','2','3'])
'1 2 3'
Run Code Online (Sandbox Code Playgroud)
您可以' '使用项目之间的任何字符串替换.