Below I have a List of the lowercase alphabet. My task is to get the index of a lowercase letter from the list and add the shift. The shift can vary and be other than 1000. It could also be 50000 or 10 etc. If the index + shift is larger than 25, it should continue counting from "a" until (index + shift) has been reached and return the letter. I am not allowed to use libraries.
My solution doesn't work for big shifts like 1000
shift = 1000
alphaList = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
index = alphaList.index('u')
index = (index + shift) - len(alphaList) # this part has to be adjusted
print(index)
print(alphaList[index])
Result should be: 'g'
what I get is:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-20-8d37e597ee25> in <module>
5 index = (index + shift) - len(alphaList)
6 print(index)
----> 7 print(alphaList[index])
IndexError: list index out of range
----------------------------------------------------------------------------