### Preface
You are currently working together with a local community to build a school teaching children how to code. First plans have been made and the community wants to decide on the best location for the coding school.
In order to make this decision data about the location of students and potential locations is collected. 

### Problem
In order to be able to attract and teach as many students as possible we want to minimize the total traveling distance for potential students. The streets system is organized in a traditional grid system and students can only travel horizontally or vertically (not diagonal).

The locations of interested students is given as an array with the first value of each entry presenting the x coordinate and the second value presenting the y coordinate:
```python
students = [[3,7],[2,2],[14,1], ...];
```
Potential locations are passed as an array of objects with an unique id, a x and y coordinate:
```python
locations = [{"id": 1, "x": 3, "y": 4}, {"id": 2, "x": 8, "y": 2}, ...];
```

Your task is now to evaluate which of the school locations would be best to minimize the distance for all potential students to the school.

The desired output should consist of a string indicating the ID of the best suitable location and the x and y coordinates in the following form:

```
"The best location is number 1 with the coordinates x = 3 and y = 4"
```

Source: codewars | Difficulty: EASY

Starter code: def optimum_location(students, locations):
	

Solutions:
def optimum_location(students, locations):
	m = min(locations, key=lambda loc: sum((abs(loc['x'] - s[0]) + abs(loc['y'] - s[1]) for s in students)))
	return 'The best location is number %d with the coordinates x = %d and y = %d' % (m['id'], m['x'], m['y'])


def manhattan(p1, p2):
	return sum((abs(b - a) for (a, b) in zip(p1, p2)))

def optimum_location(students, locations):
	return 'The best location is number {id:} with the coordinates x = {x:} and y = {y:}'.format(**min((loc for loc in locations), key=lambda l: sum((manhattan(s, (l['x'], l['y'])) for s in students))))


def optimum_location(students, locations):
	o = min(locations, key=lambda loc: sum((abs(x - loc['x']) + abs(y - loc['y']) for (x, y) in students)))
	return 'The best location is number %s with the coordinates x = %s and y = %s' % (o['id'], o['x'], o['y'])


def optimum_location(students, locations):
	best = min(locations, key=lambda location: distance(students, location))
	return 'The best location is number {id} with the coordinates x = {x} and y = {y}'.format(**best)

def distance(students, location):
	return sum((sum((abs(s[i] - location[j]) for (i, j) in ((0, 'x'), (1, 'y')))) for s in students))


d = lambda a, b, c, d: abs(d - b) + abs(c - a)
optimum_location = lambda st, lc: 'The best location is number {} with the coordinates x = {} and y = {}'.format(*min(([sum((d(*n, i['x'], i['y']) for n in st)), i['id'], i['x'], i['y']] for i in lc))[1:])


def optimum_location(students, locations):
	return 'The best location is number %(id)d with the coordinates x = %(x)d and y = %(y)d' % min(locations, key=lambda l: sum((abs(x - l['x']) + abs(y - l['y']) for (x, y) in students)))


def optimum_location(students, locations):

	def total_distance(loc):
		x_dist = sum((abs(loc['x'] - x) for (x, y) in students))
		y_dist = sum((abs(loc['y'] - y) for (x, y) in students))
		return x_dist + y_dist
	best_loc = min(locations, key=total_distance)
	template = 'The best location is number {id} with the coordinates x = {x} and y = {y}'
	return template.format(**best_loc)


def optimum_location(students, locations, optimal=(float('inf'),)):
	for loc in locations:
		distance = sum((abs(x - loc['x']) + abs(y - loc['y']) for (x, y) in students))
		if distance < optimal[0]:
			optimal = (distance, loc['id'], loc['x'], loc['y'])
	return 'The best location is number %s with the coordinates x = %s and y = %s' % optimal[1:]