python and bidirectional hit
1
0
Entering edit mode
6.5 years ago
v27 ▴ 10

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?

python best bidirectional hit • 1.6k views
ADD COMMENT
2
Entering edit mode

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 REPLY
1
Entering edit mode

The print function has an argument that you can use

print("something", end = "")

end can be any char or scape char

ADD REPLY
1
Entering edit mode
6.5 years ago

Try the .rstrip() method

ADD COMMENT

Login before adding your answer.

Traffic: 2112 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6