Question: python and bidirectional hit
0
gravatar for v27
2.2 years ago by
v2710
v2710 wrote:

i have written a program to detect the bidirectional hit. which is as follows

query = open("abc.txt","r").readlines()
database = open("cba","r").readlines()

Q2Ddict = {}
for line in query:
Q2Ddict[line.rsplit()[0]] = line.rsplit()[1]

D2Qdict = {}
for line in database:
#print(line.rsplit()[0],line.rsplit()[1])
D2Qdict[line.rsplit()[0]] = line.rsplit()[1]

for qtd,dbs in Q2Ddict.items():
for dbq,qts in D2Qdict.items():
if(qtd == qts and dbs == dbq):
print(qtd,dbs)

and the output generated is :

WP_003691339.1 WP_003691339.1
WP_010360713.1 WP_010360713.1
WP_003690758.1 WP_003690758.1
WP_003688953.1 WP_003688953.1
WP_047916891.1 WP_012503426.1
WP_002244992.1 WP_002244992.1
WP_003688378.1 WP_010356285.1

the problem is : that after every a new line is being inserted. (to remove that in perl there is a command chomp). how and where to use a similar command in python?

ADD COMMENTlink modified 2.2 years ago • written 2.2 years ago by v2710
2

I don't know if I understand your question, but print() will put a new line at the end unless you tell it not to (print(, end="")). What's your desired output?

ADD REPLYlink modified 2.2 years ago • written 2.2 years ago by goodez480
1

The print function has an argument that you can use

print("something", end = "")

end can be any char or scape char

ADD REPLYlink written 2.2 years ago by mohammadhassanj110
1
gravatar for Bastien Hervé
2.2 years ago by
Bastien Hervé4.7k
Karolinska Institutet, Sweden
Bastien Hervé4.7k wrote:

Try the .rstrip() method

ADD COMMENTlink written 2.2 years ago by Bastien Hervé4.7k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1096 users visited in the last hour