Many websites use weighted averages of various polls to make projections for elections. They’re weighted based on a variety of factors, such as historical accuracy of the polling firm, sample size, as well as date(s). The weights, in this kata, are already calculated for you. All you need to do is convert a set of polls with weights, into a fixed projection for the result.

#### Task:

Your job is to convert an array of candidates (variable name `candidates`) and an array of polls (variable name `polls`), each poll with two parts, a result and a weight, into a guess of the result, with each value rounded to one decimal place, through use of a weighted average. Weights can be zero! Don't worry about the sum not totalling 100. The final result should be a hash in Ruby and Crystal, dictionary in Python, or object in JS in the format shown below:

```python
{ 
  "": "",
  "": "",
  ...
}

For your convenience, a function named round1 has been defined for you. You can
use it to round to the nearest tenth correctly (due to the inaccuracy of round
and floats in general).
```

_The input should not be modified._

#### Calculation for projections:

```
[(poll1 * weight1) + (poll2 * weight2) + ...] / (weight1 + weight2 + ...)
```

#### An example:

```python
candidates = ['A', 'B', 'C']

poll1res = [20, 30, 50]
poll1wt = 1
poll1 = [poll1res, poll1wt]

poll2res = [40, 40, 20]
poll2wt = 0.5
poll2 = [poll2res, poll2wt]

poll3res = [50, 40, 10]
poll3wt = 2
poll3 = [poll3res, poll3wt]

polls = [poll1, poll2, poll3]

predict(candidates, polls)
#=> {
     'A': 40,
     'B': 37.1,
     'C': 22.9
    }

# because...

candidate 'A' weighted average
  = ((20 * 1) + (40 * 0.5) + (50 * 2)) / (1 + 0.5 + 2)
  = (20 + 20 + 100) / 3.5
  = 140 / 3.5
  = 40

candidate 'B' weighted average
  = ((30 * 1) + (40 * 0.5) + (40 * 2)) / (1 + 0.5 + 2)
  = (30 + 20 + 80) / 3.5
  = 130 / 3.5
  = 37.142857...
  ≈ 37.1 (round to nearest tenth)

candidate 'C' weighted average
  = ((50 * 1) + (20 * 0.5) + (10 * 2)) / (1 + 0.5 + 2)
  = (50 + 10 + 20) / 3.5
  = 80 / 3.5
  = 22.857142...
  ≈ 22.9 (round to nearest tenth)
```

Also check out my other creations — [Keep the Order](https://www.codewars.com/kata/keep-the-order), [Naming Files](https://www.codewars.com/kata/naming-files), [Square and Cubic Factors](https://www.codewars.com/kata/square-and-cubic-factors), [Identify Case](https://www.codewars.com/kata/identify-case), [Split Without Loss](https://www.codewars.com/kata/split-without-loss), [Adding Fractions](https://www.codewars.com/kata/adding-fractions),
[Random Integers](https://www.codewars.com/kata/random-integers), [Implement String#transpose](https://www.codewars.com/kata/implement-string-number-transpose), [Implement Array#transpose!](https://www.codewars.com/kata/implement-array-number-transpose), [Arrays and Procs #1](https://www.codewars.com/kata/arrays-and-procs-number-1), and [Arrays and Procs #2](https://www.codewars.com/kata/arrays-and-procs-number-2).

If you notice any issues or have any suggestions/comments whatsoever, please don't hesitate to mark an issue or just comment. Thanks!

Difficulty: EASY
Tags: Fundamentals

Starter code:
def predict(candidates, polls):
	

Solutions:
def predict(candidates, polls):
	x = zip(*[list(map(lambda i: i * weight, poll)) for (poll, weight) in polls])
	x = list(map(round1, map(lambda i: sum(i) / sum([i[1] for i in polls]), x)))
	return dict(zip(candidates, x))


def predict(candidates, polls):
	weight = sum((w for (_, w) in polls))
	scores = zip(*([s * w for s in r] for (r, w) in polls))
	return dict(zip(candidates, (round1(sum(s) / weight) for s in scores)))


from operator import itemgetter
from numpy import average

def predict(candidates, polls):
	votes = zip(*map(itemgetter(0), polls))
	weights = list(map(itemgetter(1), polls))
	return {x: round1(average(next(votes), weights=weights)) for x in candidates}


def predict(cnd, p):
	(res, wt) = list(zip(*p))
	return {j: round1(sum((k * l for (k, l) in zip(list(zip(*res))[i], wt))) / sum(wt)) for (i, j) in enumerate(cnd)}


def predict(cnd, p):
	(wt, res, polls) = ([], [], {})
	for i in p:
		wt.append(i[1])
		res.append(i[0])
	(wt_sum, res) = (sum(wt), list(zip(*res)))
	for (i, j) in enumerate(cnd):
		polls[j] = round1(sum((k * l for (k, l) in zip(res[i], wt))) / wt_sum)
	return polls


def predict(candidates, polls):
	total_weight = sum((w for (p, w) in polls))
	return {c: round1(sum((ps[i] * w for (ps, w) in polls)) / total_weight) for (i, c) in enumerate(candidates)}


import math

def predict(candidates, polls):
	t = {}
	for (i, j) in enumerate(candidates):
		m = 0
		n = 0
		for z in polls:
			n += z[1]
			m += z[0][i] * z[1]
		t[j] = round1(m / n)
	return t


def predict(candidates, polls):
	res = dict()
	for i in range(len(candidates)):
		p = 0
		s = 0
		for poll in polls:
			p += poll[0][i] * poll[1]
			s += poll[1]
		res[candidates[i]] = round1(p / s)
	return res


predict = lambda cs, ps: {c: round1(sum((p[0][i] * p[1] for p in ps)) / sum((p[1] for p in ps))) for (i, c) in enumerate(cs)}


def predict(candidates, polls):
	wts = [i[1] for i in polls]
	return dict(zip(candidates, map(lambda z: round1(sum((a * b for (a, b) in zip(z, wts))) / sum(wts)), zip(*(i[0] for i in polls)))))