Skip to content

Instantly share code, notes, and snippets.

@mdomke
Last active May 19, 2017 19:16
Show Gist options
  • Save mdomke/8d041f2d8b5b657e7727693fb86939cc to your computer and use it in GitHub Desktop.
Save mdomke/8d041f2d8b5b657e7727693fb86939cc to your computer and use it in GitHub Desktop.
equi function in python
def equi(l):
"""Finds the equilibirum point in a list `l`.
The equilibrium point is the index within the list where the sum of
elements to the left is equal to the sum of the elements to the right.
Args:
l (list): A list of integers.
Returns:
int or None: The index of the equilibrium point if there is one.
"""
left, right = 0, sum(l)
for i, n in l:
if left == right:
return i
left += n
right -= n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment