Your wizard cousin works at a Quidditch stadium and wants you to write a function that calculates the points for the Quidditch scoreboard! 

# Story

Quidditch is a sport with two teams. The teams score goals by throwing the Quaffle through a hoop, each goal is worth **10 points**.

The referee also deducts 30 points (**- 30 points**) from the team who are guilty of carrying out any of these fouls: Blatching, Blurting, Bumphing, Haverstacking, Quaffle-pocking, Stooging 

The match is concluded when the Snitch is caught, and catching the Snitch is worth **150 points**. Let's say a Quaffle goes through the hoop just seconds after the Snitch is caught, in that case the points of that goal should not end up on the scoreboard seeing as the match is already concluded. 

You don't need any prior knowledge of how Quidditch works in order to complete this kata, but if you want to read up on what it is, here's a link: https://en.wikipedia.org/wiki/Quidditch

# Task

You will be given a string with two arguments, the first argument will tell you which teams are playing and the second argument tells you what's happened in the match. Calculate the points and return a string containing the teams final scores, with the team names sorted in the same order as in the first argument. 

# Examples:

# Given an input of:

# The expected output would be:

Separate the team names from their respective points with a colon and separate the two teams with a comma. 

Good luck!

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code: def quidditch_scoreboard(teams, actions):
	

Solutions:
def quidditch_scoreboard(teams, actions):
	teams = {i: 0 for i in teams.split(' vs ')}
	for i in actions.split(', '):
		(team, action) = i.split(': ')
		if 'goal' in action:
			teams[team] += 10
		elif 'foul' in action:
			teams[team] -= 30
		elif 'Snitch' in action:
			teams[team] += 150
			break
	return ', '.join(('{}: {}'.format(i, teams[i]) for i in teams))


def quidditch_scoreboard(teams, actions):

	def formatter(team, pts):
		return ', '.join((f'{t}: {p}' for (p, t) in zip(pts, teams)))
	(pts, teams) = ([0, 0], teams.split(' vs '))
	for act in actions.split(', '):
		for (i, t) in enumerate(teams):
			p = act.startswith(t) * (10 * act.endswith('goal') + 150 * act.endswith('Snitch') - 30 * act.endswith('foul'))
			pts[i] += p
			if p == 150:
				return formatter(teams, pts)
	return formatter(teams, pts)


import re
from itertools import chain
_VALUE = {'foul': -30, 'goal': 10, 'Snitch': 150}
_TEAMS = re.compile('(.+) vs (.+)')
_ACTION = re.compile('(.+): \\S+ (\\S+)')

def quidditch_scoreboard(teams, actions):
	scores = {team: 0 for team in _TEAMS.match(teams).groups()}
	for action in actions.split(', '):
		(team, event) = _ACTION.match(action).groups()
		scores[team] += _VALUE[event]
		if event == 'Snitch':
			break
	return '{}: {}, {}: {}'.format(*chain.from_iterable(list(scores.items())))


def quidditch_scoreboard(teams, actions):
	(t1, t2) = teams.split(' vs ')
	D = {t1: 0, t2: 0}
	for action in actions.split(', '):
		(t, a) = action.split(': ')
		if a.endswith('goal'):
			D[t] += 10
		elif a.endswith('foul'):
			D[t] -= 30
		else:
			D[t] += 150
			break
	return ', '.join((f'{k}: {v}' for (k, v) in D.items()))


from collections import Counter

def quidditch_scoreboard(teams, actions):
	ts = teams.split(' vs ')
	scores = dict.fromkeys(ts, 0)
	for action in actions.split(', '):
		(team, a) = action.split(': ')
		if a == 'Caught Snitch':
			scores[team] += 150
			break
		elif a == 'Quaffle goal':
			scores[team] += 10
		elif a.endswith('foul'):
			scores[team] -= 30
	return ', '.join((f'{team}: {scores[team]}' for team in ts))


import re

def quidditch_scoreboard(teams, actions):
	points = {'goal': 10, 'foul': -30, 'Caught': 150}
	teams = teams.split(' vs ')
	scores = [0, 0]
	actions = re.findall('(\\w[\\w ]+): .*?(goal|foul|Caught)', actions.partition(' Snitch')[0])
	for (team, action) in actions:
		scores[teams.index(team)] += points[action]
	return '{0[0]}: {1[0]}, {0[1]}: {1[1]}'.format(teams, scores)


import re
score_dict = {'Quaffle goal': 10, 'Caught Snitch': 150}

def quidditch_scoreboard(teams, actions):
	actions = re.sub('Caught Snitch.+', 'Caught Snitch', actions)
	actions = [action.split(':') for action in actions.split(',')]
	actions = [[item.strip() for item in action] for action in actions]
	(team_one, team_two) = teams.split(' vs ')
	team_one_sum = sum([score_dict.get(a[1], -30) for a in actions if a[0] == team_one])
	team_two_sum = sum([score_dict.get(a[1], -30) for a in actions if a[0] == team_two])
	return f'{team_one}: {team_one_sum}, {team_two}: {team_two_sum}'


def quidditch_scoreboard(teams, actions):
	t = teams.split(' vs ')
	D = {n: 0 for n in t}
	for a in actions.split(','):
		D[a[:a.find(':')].strip()] += [p for (w, p) in [('Snitch', 150), ('goal', 10), ('foul', -30)] if w in a].pop()
		if 'Snitch' in a:
			break
	return f'{t[0]}: {D[t[0]]}, {t[1]}: {D[t[1]]}'


def quidditch_scoreboard(t, s, x=0, y=0):
	(a, b) = t.split(' vs ')
	for X in s.split(','):
		(k, v) = X.strip().split(':')
		if k == a:
			x += 10 if ' Quaffle goal' == v else 150 if ' Caught Snitch' == v else -30
		if k == b:
			y += 10 if ' Quaffle goal' == v else 150 if ' Caught Snitch' == v else -30
		if ' Caught Snitch' == v:
			break
	return '%s: %d, %s: %d' % (a, x, b, y)


def quidditch_scoreboard(teams, actions):
	(team_1, team_2) = (teams.split(' vs ')[0], teams.split(' vs ')[1])
	fouls = ['Blatching foul', 'Blurting foul', 'Bumphing foul', 'Haverstacking foul', 'Quaffle-pocking foul', 'Stooging foul']
	scores = {'Quaffle goal': 10, 'Caught Snitch': 150}
	(scores_1, scores_2) = (0, 0)
	for i in actions.split(','):
		if i.split(': ')[0].strip() == team_1:
			if i.split(': ')[1].strip() in scores:
				if i.split(': ')[1].strip() == 'Caught Snitch':
					scores_1 += scores[i.split(': ')[1].strip()]
					break
				else:
					scores_1 += scores[i.split(': ')[1].strip()]
			if i.split(': ')[1].strip() in fouls:
				scores_1 -= 30
		elif i.split(': ')[0].strip() == team_2:
			if i.split(': ')[1].strip() in scores:
				if i.split(': ')[1].strip() == 'Caught Snitch':
					scores_2 += scores[i.split(': ')[1].strip()]
					break
				else:
					scores_2 += scores[i.split(': ')[1].strip()]
			if i.split(': ')[1].strip() in fouls:
				scores_2 -= 30
	return '{}: {}, {}: {}'.format(team_1, scores_1, team_2, scores_2)