Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created Feb 7, 2020
Embed
What would you like to do?
Codecademy export
#Write your function here
def middle_element(lst):
if len(lst) % 2 == 0:
index1 = int(len(lst)/2)
index2 = int(len(lst)/2 - 1)
value1 = lst[index1]
value2 = lst[index2]
average = (value1+value2)/2
return average
else:
index1 = int(len(lst)/2)
return lst[index1]
#Uncomment the line below when your function is done
print(middle_element([5, 2, -10, -4, 4, 5]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment