I attempted the middle elements practice but I wasn’t able to get it and I don’t understand how the solution works.

This is what I tried originally.

```
#Write your function here
def middle_element(lst):
for element in lst:
if len(lst) % 2 == 0:
middle = len(lst)/2
return middle
elif len(lst) % 2 != 0:
middle1 = list[2]
middle2 = list[-2]
average = middle1 + middle2 /2
return average
#Uncomment the line below when your function is done
print(middle_element([5, 2, -10, -4, 4, 5]))
```

This is the solution and the prompt

**Create a function called middle_element that has one parameter named lst .**

**If there are an odd number of elements in lst , the function should return the middle element. If there are an even number of elements, the function should return the average of the middle two elements.**

```
#Write your function here
def middle_element(lst):
if len(lst) % 2 == 0:
sum = lst[int(len(lst)/2)] + lst[int(len(lst)/2) - 1]
return sum / 2
else:
return lst[int(len(lst)/2)]
#Uncomment the line below when your function is done
print(middle_element([5, 2, -10, -4, 4, 5]))
```

I understand the part where they checked in the length of the list was odd or even. I also see where I got confused between and odd and even list. If it was even then two elements would be left in the

My question is…what happened here??

`sum = lst[int(len(lst)/2)] + lst[int(len(lst)/2) - 1]`