打印元素不在列表中 [英] Printing elements out of list
问题描述
我有一个特定的检查要完成,如果检查满意,我希望将结果打印出来.下面是代码:
I have a certain check to be done and if the check satisfies, I want the result to be printed. Below is the code:
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
上面的代码很好用,但是当我打印j时,它打印的像['351','342'],但我希望得到351342(中间有一个空格).由于更多的是python问题,因此我没有包括输入文件(基本上它们只是数字).
The above code works great but when I print j, it prints like ['351', '342'] but I am expecting to get 351 342 (with one space in between). Since it is more of a python question, I have not included the input files (basically they are just numbers).
有人可以帮助我吗?
干杯
Chavanak
推荐答案
To convert a list of strings to a single string with spaces in between the lists's items, use ' '.join(seq)
.
>>> ' '.join(['1','2','3'])
'1 2 3'
您可以将' '
替换为项目之间想要的任何字符串.
You can replace ' '
with whatever string you want in between the items.
这篇关于打印元素不在列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!