Jul-10-2018, 08:28 AM
Dear All,
I think my question would be easy for most, not just for me.
I've spent two day to solve it, but I'm now giving up!
Please advice...
The rank is 0 in A group.
The rank is 3 in B group.
The rank is 2 in C group.
The rank is 0 in D group.
But I got the result as below:
The rank is [('B', '3')] www.ddd.com
The rank is [('C', '2')] www.ddd.com
Could you please give me your teachings?
Thank you for your interesting.
I think my question would be easy for most, not just for me.
I've spent two day to solve it, but I'm now giving up!
Please advice...
import re data = """ t=A n=1 www.aaa.com t=A n=2 www.bbb.com t=A n=3 www.ccc.com t=B n=1 www.aaa.com t=B n=2 www.bbb.com t=B n=3 www.ddd.com t=C n=1 www.bbb.com t=C n=2 www.ddd.com t=C n=3 www.ccc.com t=D n=1 www.aaa.com t=D n=2 www.bbb.com t=D n=3 www.ccc.com t=D n=4 www.eee.com """ domain = "www.ddd.com" for line in data.splitlines(): tn = re.compile("t=(\w)\s+n=(\d)") get = tn.findall(line) get = str(get) if domain in line: print("The rank is " + get + " " + domain)From above code, I hope to get the result as below;
The rank is 0 in A group.
The rank is 3 in B group.
The rank is 2 in C group.
The rank is 0 in D group.
But I got the result as below:
The rank is [('B', '3')] www.ddd.com
The rank is [('C', '2')] www.ddd.com
Could you please give me your teachings?
Thank you for your interesting.