>find the letter with the highest index in alphabetical order
initialise highest_index to 0
initialise highest_index_character to empty string
>>Find the highest index of the character and the relevant character in the name
initialise highest_index to 0
initialise highest_index_character to empty string
for each character in the name:
if character's index in alphabet is higher than in highest_index
set highest_index to character's index
set highest_index_character to character
return string of highest_index and highest_index_character
code
alphabet=["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"]defalphabet_index(alphabet:list,name:str):# The name are in upper case, but alphabet is in lower case
name=name.lower()# initialise highest_index to 0
highest_index=0# initialise highest_index_character to empty string
highest_index_character=str()# for each character in the name:
forcharacterinname:# if character's index in alphabet is higher than in highest_index
ifalphabet.index(character)+1>highest_index:# set highest_index to character's index
highest_index=alphabet.index(character)+1# set highest_index_character to character
highest_index_character=character# return string of highest_index and highest_index_character
returnstr(str(highest_index)+highest_index_character)
Other solution
don't find any particular impressive code. If there is shorter way to do this, please let me know.
My reflection
This takes me long time to write out the algorithm in appropriate formate, need to practice more
Top comments (0)