나는 이렇게 학습한다/Algorithm & SQL
Highest Scoring Word
daco2020
2022. 7. 28. 18:55
Given a string of words, you need to find the highest scoring word.
Each letter of a word scores points according to its position in the alphabet: a = 1, b = 2, c = 3 etc.
You need to return the highest scoring word as a string.
If two words score the same, return the word that appears earliest in the original string.
All letters will be lowercase and all inputs will be valid.
Solution:
def high(x):
x = x.lower().split(" ")
points = [sum([ord(i)-ord("a")+1 for i in j]) for j in x]
return x[points.index(max(points))]