A checksum is an algorithm that scans a packet of data and returns a single number. The idea is that if the packet is changed, the checksum will also change, so checksums are often used for detecting
transmission errors, validating document contents, and in many other situations where it is necessary to detect undesirable changes in data.

For this problem, you will implement a checksum algorithm called Quicksum. A Quicksum packet allows only uppercase letters and spaces. It always begins and ends with an uppercase letter. 

Otherwise, spaces and uppercase letters can occur in any combination, including consecutive spaces.

A Quicksum is the sum of the products of each character’s position in the packet times the character’s value. A space has a value of zero, while letters have a value equal to their position in the alphabet. 

So, ```A = 1```, ```B = 2```, etc., through ```Z = 26```. Here are example Quicksum calculations for the packets “ACM” and “A C M”:
 
  ACM
1 × 1 + 2 × 3 + 3 × 13 = 46 

A C M
1 x 1 + 3 x 3 + 5 * 13 = 75


When the packet doesn't have only uppercase letters and spaces or just spaces the result to quicksum have to be zero (0).
 
  AbqTH #5 = 0

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def quicksum(packet):
	

Solutions:
from string import ascii_uppercase
values = {x: i for (i, x) in enumerate(ascii_uppercase, 1)}

def quicksum(packet):
	return sum((values.get(c, 0) * i for (i, c) in enumerate(packet, 1))) * all((c.isspace() or c.isupper() for c in packet))


def quicksum(packet):
	result = 0
	for (idx, char) in enumerate(packet, 1):
		if char.isupper():
			result += idx * (ord(char) - 64)
		elif char == ' ':
			continue
		else:
			return 0
	return result


import re

def quicksum(packet):
	isValid = re.match('[A-Z ]*$', packet)
	value = sum((i * (ord(c) - 64) for (i, c) in enumerate(packet, 1) if c != ' '))
	return isValid and value or 0


def quicksum(packet):
	if not packet.replace(' ', '').isalpha() or not packet.isupper():
		return 0
	return sum(((i + 1) * (1 + ord(l) - ord('A')) if l.isalpha() else 0 for (i, l) in enumerate(packet)))


def quicksum(packet):
	if all((True if ord(x) > 64 and ord(x) < 91 or ord(x) == 32 else False for x in packet)):
		return sum((0 if x == ' ' else (ord(x) - 64) * y for (y, x) in enumerate(packet, 1)))
	return 0


from string import ascii_uppercase
AZ = dict(list(zip(' ' + ascii_uppercase, list(range(27)))))

def quicksum(packet):
	result = 0
	for (i, a) in enumerate(packet, 1):
		try:
			result += AZ[a] * i
		except KeyError:
			return 0
	return result


def quicksum(packet):
	alph = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	su = 0
	for (k, v) in enumerate(packet):
		if v not in alph:
			return 0
		su += (k + 1) * alph.index(v)
	return su


quicksum = lambda p: sum((i * (ord(e) - 64) * (e != ' ') for (i, e) in enumerate(p, 1))) * all((x in __import__('string').ascii_uppercase + ' ' for x in p))


VALID = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def quicksum(packet):
	return 0 if set(packet) - set(VALID) else sum((VALID.index(char) * i for (i, char) in enumerate(packet, 1)))


from string import ascii_uppercase as auc

def quicksum(packet):
	d = {v: k for (k, v) in enumerate(' ' + auc)}
	try:
		return sum((c * d[s] for (c, s) in enumerate(packet, 1)))
	except:
		return 0