Python Code Challenges Lists (Advanced) Exercises 5

Hey guys this is my code until now, which outputs <function middle_element at 0x7f2cf8573e18>. I was wondering, I totally forgot, how do I display the value of this list?

This is my code:

#Write your function here

def middle_element(lst):

if len(lst) % 2 == 0:

return str(middle_element)

else:

return str(middle_element) / len(lst)

#Uncomment the line below when your function is done

print(middle_element([5, 2, -10, -4, 4, 5]))

If you’re posting code to the forums please see- How do I format code in my posts? Without the formatting it is much harder for anyone else to understand.

Be careful with names here. You have a function called middle_element. Inside that function you use the name middle_element, which refers to the function…
That’s probably not what you want.

Consider how to actually get the middle element. If you can’t solve it with code at first try it with pen and paper. Once you have a solution there it’s a matter of translating that to code which is often easier than going head-first and trying to do two tasks at once.

To access items from a list you refer the index number. For example:

lst = ['eggs', 'ham', 'spam']

print(lst[0])  
eggs

Okay thanks for the help! I managed to solve the problem now. Thanks a lot and have a nice day. I will use the codebyte for next time.