I'm trying to re-run some of the Python Challenge levels in the second task it is necessary to rearrange the letters alphabetically in the text.

from string import ascii_lowercase as low file=open("pch0.txt","r").read() low=list(low) result = "" for i in file: if i == low[24] or i == low[25]: result += low[int(low.index(i)-24)] if i in low: result += low[int(low.index(i))+2] else: result += i 

in the end it turns out "i hope you didnt tra" everything seems to be going fine up to the 20th character. And now the second day I can not understand why.

PS in the file "pch0.txt" text

"g fmcd"

    1 answer 1

    You have exceeded the number of characters in the array. Try this.

     from string import ascii_lowercase as low file = open("pch0.txt", "r").read() low = list(low) result = "" for i in file: if i == low[24] or i == low[25]: result += low[int(low.index(i) - 24)] if i in low: if int(low.index(i) + 2) < 25: result += low[int(low.index(i) + 2)] else: result += i print(result) # i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url.