lets say i have 2 lists:
lista = [1,2,3,5,6,7]
listb = [4,5,6,7,8,9,10]

The lists can be different lengths, and may not allways be unequal lengths.

The higher average will allways be in listb, so that is the 1 constant we can rely on.

This works for even teams:

``````average = float(sum(lista) + sum(listb)) / \
float(len(lista) + len(listb))

value = round(abs((average * len(lista)) - sum(lista)))``````

value would return the number i needed to move from listb to lista

i tried this,but it doesnt seem to work:

``````Offset = float(len(listb) - len(lista))

value = round(((len(lista) * sum(lista)) + \
(len(lista) * Offset) - \
(average * len(lista) - \
(average * Offset))) / \
(len(lista) * Offset))``````

any ideas?

4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by vegaseat

Huh? You've said what you've done, but not what you're trying to do...

Is the function a fictitious theory or for a specific reason?

You are getting tangled up in a forest of parenthesis. There is one missing in the mess. It is best to break things into smaller parts ...

``````list_a = [1,2,3,5,6,7]
list_b = [4,5,6,7,8,9,10]
# for convenience
list_ab = list_a + list_b

average = float(sum(list_ab))/len(list_ab)
offset = float(len(list_b) - len(list_a))

a = len(list_a) * sum(list_a)
b = len(list_a) * offset
c = average * len(list_a)
d = average * offset

value = (a + b - c - d)/b

print value
print round(value)``````

Edited by vegaseat: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.