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.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Data structures

Starter code: def high(x):
	

Solutions:
def high(x):
	return max(x.split(), key=lambda k: sum((ord(c) - 96 for c in k)))


def high(x):
	words = x.split(' ')
	list = []
	for i in words:
		scores = [sum([ord(char) - 96 for char in i])]
		list.append(scores)
	return words[list.index(max(list))]


def high(x):
	scoreboard = ['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']
	heck = x.split()
	score = 0
	score_final = 0
	big_word = []
	for each in heck:
		print(each)
		for every in each:
			if every in scoreboard:
				score = score + scoreboard.index(every) + 1
				print(score)
		if score > score_final:
			score_final = score
			big_word = each
			score = 0
		else:
			score = 0
	return big_word


def high(words):
	return max(words.split(), key=lambda word: sum((ord(c) - ord('a') + 1 for c in word.lower())))


def high(x):
	highest_score = 0
	for word in x.split(' '):
		score = sum((ord(c) - 96 for c in word))
		if score > highest_score:
			highest_score = score
			highest_word = word
	return highest_word


def xx(m):
	a = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
	n = 0
	for i in m:
		n += a[i]
	return n

def high(x):
	x = x.split()
	(m, n) = (x[0], xx(x[0]))
	for i in x[1:]:
		if xx(i) > n:
			m = i
			n = xx(i)
	return m


def high(x):
	(s, n) = (x.split(), [sum((ord(c) - 96 for c in y)) for y in x.split()])
	return s[n.index(max(n))]


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']

def high(x):
	strings = list(x.split())
	array = []
	for word in strings:
		value = 0
		for letter in word:
			value += alphabet.index(letter) + 1
		array.append([value, word])
	array.sort()
	return array[-1][1]


def high(s):
	return max(((sum((ord(c) - 96 for c in x)), x) for x in s.split()))[1]


from string import ascii_lowercase

def high(x):
	letter_worth = {letter: int(index) for (index, letter) in enumerate(ascii_lowercase, start=1)}
	words = x.split()
	total = []
	for word in words:
		count = 0
		for letter in word:
			count += letter_worth.get(letter)
		total.append(count)
	return words[total.index(max(total))]