-
Notifications
You must be signed in to change notification settings - Fork 1
Functions (2) code_cyclic(index,letter)
Yes, you know this function, but it is required that we take a quick look at it:
def code_cyclic(index, letter):
'''Cyclic transform of letters based on the index of the letter in the word and
that in the series of alphabets in order
Arguments (Parameters, I guess):
_____________
index - index of the letter in the word (type : int)
letter - the letter to be coded (type : str)'''
# The formula used here is : 26 * (index of the letter in word - 1) + (index of the letter in the alphabets)
# I had to use a separate variable 'index' to avoid the confusion the program gets when
# choosing the index of the letter (eg., in the case of "HELLO", there are 2 'L's and this will cause confusion
# This problem has been solved in the upcoming function.
return 26 * index + (find_index(letter) + 1)
Sorry for making such clumsy code by adding big comments (instead of short, concise and implicit ones).
Here, we implement the formula referred to in the prologue , but alongside that, we add that missing '1' to the index of the letter to get the correct position value of the letter.
There is a silly reason to why I call this function code_cyclic
: since this function is going to be used in a cyclic process and that the value yielded by this function for the same letter varies according to the letter's position in the word (eg. : 'Hello' - here, we have 2 'l's at different positions which alters the value yielded by the function for the letter 'l'). It is also to be noted that I used the find_index
function (whose making would sound unnecessary but did indeed work well for me by reducing the amount of time I used to make this code)