The program must print the name which is alphabetically the last one out of 8 elements.
The names/words can be inputted in any way through code.
I think I should be using lists and in range()
here. I had an idea of comparing the first/second/third/... letter of the input name with the letters of the previous one and then putting it at the end of the list or in front of the previous one (depending on the comparison), and then repeating that for the next name. At the end the program would print the last member of the list.
If you have a mix of capitalized words and lowercase words you could do this:
from string import capwords
words = ['bear', 'Apple', 'Zebra','horse']
words.sort(key = lambda k : k.lower())
answer = words[-1]
Result:
>>> answer
'Zebra'
>>> words
['Apple', 'bear', 'horse', 'Zebra']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With