May-27-2020, 03:52 PM
Could anyone help me to solve the question on https://www.ohjelmointiputka.net/postit/...nnus=mpera
In English, it goes like this. Given a string S, find the longest string s such that s concatenated by itself is a substring of S.
I was able to solve it by bash:
So in Python, how can I call a bash script and get the result string to a variable such that I can use it in Python?
In English, it goes like this. Given a string S, find the longest string s such that s concatenated by itself is a substring of S.
I was able to solve it by bash:
echo hfhfggccaggccagccafff | grep -Po '(.*)\K\1' | awk 'length > l {l=length;s=$0} END{print s}' ggccaBut as I tried to solve in Python, I got an error:
import subprocess s = 'hfhfggccaggccagccafff' command = "echo hfhfggccaggccagccafff | grep -Po '(.*)\K\1' | awk 'length > l {l=length;s=$0} END{print s}" #output = subprocess.check_output(command, shell=True) output = subprocess.run(command, stdout=subprocess.PIPE) print(output.stdout)FileNotFoundError: [Errno 2] No such file or directory: "echo hfhfggccaggccagccafff | grep -Po '(.*)\\K\x01' | awk 'length > l {l=length;s=$0} END{print s}"
So in Python, how can I call a bash script and get the result string to a variable such that I can use it in Python?