I'm trying to make an easy dummy thing but I kinda stopped at something i never encounter. Making some kind of translator which should work like this:
word = "hello"
h => i (+1 position in alphabet)
e => g (+2)
l => o (+3)
l => p (+4)
o => t (+5)
but I (obviously) hit the end of the list at some point. Is there some kind of function(maybe) to loop the list?
To work it like this:
word = "maze"
m = n (+1)
a = c (+2)
z = c (+3 - loop thru the list to the start)
e = i (+4)
I was thinking of using -26 as the indexerror exception, but I'm kinda hoping there is going to be more beautiful posibility. Or maybe even easier solution overall?
Thanks!
Code:
import string
alphabet_list = []
word = "hello my friend"
x = 0
for char in string.ascii_lowercase:
alphabet_list.append(char)
### 26 chars || 0 - 25 ###
# print(alphabet_list)
for character in word:
x += 1
if character in alphabet_list:
print(alphabet_list[alphabet_list.index(character) + x])