I have the following piece of code.
result = "1/1/2010|1/2/2111"
request = "1/1/1.3.4.5.6/1/1/127.0.0.1"
replylist = result.split("|")
finalresultlist = [
f"{i.split('/')[2]}.{j.split('/')[2]}"
for i in request
for j in replylist \
if (i.split("/")[1] == j.split("/")[1])
]
print(finalresultlist)
Note: The f"{i.split('/')[2]}.{j.split('/')[2]}" concatenates the "1.3.4.5.6" with the "2010" when there is a match if (i.split("/")[1] == j.split("/")[1]) based on the value in the index [1] after each of the result and request strings are split on the '|'.
I want to return a new string, which concatenates the 1.3.4.5.6 of request with 2010 of result to return a list which contains the string: ["1.3.4.5.6.2010"]
In my current code, I get the error "list out of range". I am unable to resolve this issue.
Any help is appreciated.
requestis a string, and iterating over it (for i in request) gives you one character at a time. It looks to me like you're trying to do too many things at once.1.3.4.5.6with the2010.