반응형
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))]
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
Printer Errors (0) | 2022.07.31 |
---|---|
Build Tower (0) | 2022.07.29 |
Simple Fun #176: Reverse Letter (0) | 2022.07.27 |
Money, Money, Money (0) | 2022.07.26 |
Calculate BMI (0) | 2022.07.25 |