Magic The Gathering is a collectible card game that features wizards battling against each other with spells and creature summons. The game itself can be quite complicated to learn. In this series of katas, we'll be solving some of the situations that arise during gameplay. You won't need any prior knowledge of the game to solve these contrived problems, as I will provide you with enough information.

## Creatures

Each creature has a power and toughness. We will represent this in an array. [2, 3] means this creature has a power of 2 and a toughness of 3.

When two creatures square off, they each deal damage equal to their power to each other at the same time. If a creature takes on damage greater than or equal to their toughness, they die.

Examples:

- Creature 1 - [2, 3]
- Creature 2 - [3, 3]
- Creature 3 - [1, 4]
- Creature 4 - [4, 1]

If creature 1 battles creature 2, creature 1 dies, while 2 survives. If creature 3 battles creature 4, they both die, as 3 deals 1 damage to 4, but creature 4 only has a toughness of 1.

Write a function `battle(player1, player2)` that takes in 2 arrays of creatures. Each players' creatures battle each other in order (player1[0] battles the creature in player2[0]) and so on. If one list of creatures is longer than the other, those creatures are considered unblocked, and do not battle.

Your function should return an object (a hash in Ruby) with the keys player1 and player2 that contain the power and toughness of the surviving creatures.

Example:
```
Good luck with your battles!


Check out my other Magic The Gathering katas:


Magic The Gathering #1: Creatures
Magic The Gathering #2: Mana

Difficulty: EASY
Tags: Fundamentals

Data structures

Game theory
Skill types: Data structures

Starter code:
def battle(player1, player2):
	

Solutions:
from itertools import zip_longest

def battle(player1, player2):
	result = {'player1': [], 'player2': []}
	for ((p1, t1), (p2, t2)) in zip_longest(player1, player2, fillvalue=[0, 0]):
		if t1 > p2:
			result['player1'].append([p1, t1])
		if t2 > p1:
			result['player2'].append([p2, t2])
	return result


def battle(player1, player2):
	l1 = []
	l2 = []
	x = min(len(player1), len(player2))
	for i in range(x):
		if player1[i][0] < player2[i][1]:
			l2.append(player2[i])
		if player2[i][0] < player1[i][1]:
			l1.append(player1[i])
	l1 += player1[x:]
	l2 += player2[x:]
	return {'player1': l1, 'player2': l2}


from itertools import zip_longest

def battle(player1, player2):
	res = {'player1': [], 'player2': []}
	for (c1, c2) in zip_longest(player1, player2, fillvalue=[0, 0]):
		if c2[0] < c1[1]:
			res['player1'].append(c1)
		if c1[0] < c2[1]:
			res['player2'].append(c2)
	return res


def battle(p1, p2):
	(p, p_) = (p1[:], p2[:])
	for (i, j) in zip(p1, p2):
		if i[0] >= j[1]:
			p_.remove(j)
		if j[0] >= i[1]:
			p.remove(i)
	return {'player1': p, 'player2': p_}


from itertools import zip_longest

def battle(player1, player2):
	result = {'player1': [], 'player2': []}
	for (creature1, creature2) in zip_longest(player1, player2, fillvalue=[0, 0]):
		if creature1[1] > creature2[0]:
			result['player1'].append(creature1)
		if creature2[1] > creature1[0]:
			result['player2'].append(creature2)
	return result


def battle(player1, player2):
	rem1 = [c for (i, c) in enumerate(player1) if i >= len(player2) or c[1] > player2[i][0]]
	rem2 = [c for (i, c) in enumerate(player2) if i >= len(player1) or c[1] > player1[i][0]]
	return {'player1': rem1, 'player2': rem2}


def battle(player1, player2):
	if len(player1) > len(player2):
		min_creatures = len(player2)
	else:
		min_creatures = len(player1)
	i = min_creatures - 1
	while i >= 0:
		if player1[i][0] >= player2[i][1] and player2[i][0] >= player1[i][1]:
			del player1[i]
			del player2[i]
		elif player1[i][0] >= player2[i][1]:
			del player2[i]
		elif player2[i][0] >= player1[i][1]:
			del player1[i]
		i -= 1
	return {'player1': player1, 'player2': player2}