tags:
- code
topic: String
difficulty: Intermediate
link: https://www.codewars.com/kata/57eb8fcdf670e99d9b000272
date: 2023-12-31
Problem
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.
For example, the score of `abad` is `8` (1 + 2 + 1 + 4).
def high(x):
words = {}
for i in x.split():
words[i] = sum([ord(c)-96 for c in i])
return max(words, key=words.get)