You would like to get the 'weight' of a name by getting the sum of the ascii values. However you believe that capital letters should be worth more than mere lowercase letters. Spaces, numbers, or any other character are worth 0.

Normally in ascii

    a has a value of 97
    A has a value of 65
    ' ' has a value of 32
    0 has a value of 48

To find who has the 'weightier' name you will switch all the values so:

    A will be 97
    a will be 65
    ' ' will be 0
    0 will be 0
    etc...

For example Joe will have a weight of 254, instead of 286 using normal ascii values.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code: def get_weight(name):
	

Solutions:
def get_weight(name):
	return sum((ord(a) for a in name.swapcase() if a.isalpha()))


def get_weight(name):
	return sum((ord(c.swapcase()) for c in name if c.isalpha()))


import string as q

def get_weight(name):
	return sum((ord(char.swapcase()) for char in name if char in q.ascii_letters))


def get_weight(name):
	return sum((ord(x) for x in name.swapcase() if x.isalpha()))


get_weight = lambda s: sum((ord(c) for c in s.swapcase() if c.isalpha()))


import re

def get_weight(name):
	return sum(map(ord, re.sub('[^a-zA-Z]', '', name.swapcase())))


get_weight = lambda s: sum((ord(e) for e in s.swapcase() if e.isalpha()))


get_weight = lambda s: sum(map(ord, filter(str.isalpha, s.swapcase())))


def get_weight(name):
	return sum((ord(x) for x in filter(str.isalpha, name.swapcase())))


def get_weight(name):
	return sum((ord(n.swapcase()) for n in name if n.isalpha()))