Advanced Python Code Challenges: Lists

Was there no one else that thought some of these challenges were a huge leap compared to what you had been doing up to that point? I know that it says they are going to be difficult but without looking at the solution code of number 5 I had no idea how to really address that. Even when I looked at the solution code I was kind of taken back by how it was all linked/put together.

By no idea, I understood how to address the odd (with % 2), but finding the middle sum and dividing by two… sheesh.

I feel like I shouldn’t move on at this point. I can read what they put together but it doesn’t really click if you were to give me a similar question.


I have found this as well. The regular List Code Challenges were doable but I feel like I’ve missed a chapter trying to do these.


Those challenges are supposed to be tough, in part to force you to think seriously about applying what you’ve learned so far.

If you were able to complete the majority of those tasks, and only #5 stumped you, that’s pretty good. Spend a bit of time looking at the solution you couldn’t get yourself, see if you can work out not only what the code is doing but also what the steps are. Maybe write out, in a set of bullet points, the main steps the program goes through to get from the function being called to the output arriving at the console.

Programming, to a great extent, is simply taking something like that list of bullet points - the steps that your code has to perform - and crafting the necessary sequence of instructions to guide the computer through those steps.

I wouldn’t let a bit of confusion around those tasks stop you from continuing with the course. You can always come back later, attempt it again, and keep working at it until it makes sense. :slight_smile:


You’re right. Thanks for the confidence.

1 Like

You can use this code:

def middle_element(lst):
  mid = len(lst) // 2
  for item in lst:
    if item % 2 != 0 and len(lst) % 2 == 0:
      return (lst[mid-1]+lst[mid])/2
      return lst[mid]

I spent over 3 hours with trials and errors to solve the 5th challenge only.

What role does if item % 2 != 0 play? What is it checking for? Is it relevant?
What does for item in list: do? Is it necessary?


I was too focused on identifying the odd number. It’s my bad. Thanks for the correction.

1 Like

No worries.

Everyone gets stuck at some point - just need to remember you’re not the first person to get stuck while programming, and keep on going. :slight_smile:

1 Like

I feel the same. Until I got to the Advanced Code Challenges - Lists, I felt I was understanding both the concepts and the syntax behind whatever it was we were learning. But questions #4 and #5 feel like a leap of logic and conceptual understanding not supported by what’s taught. I was baffled by the long lines of code in #4 especially. How am I supposed to forge those links together into a chain?

I’ve been scouring these fora, StackOverflow, Programmiz, GeeksforGeeks, Quora, etc., with each little component that I think may help me (e.g., looking up how conditionals are taught on other platforms, indexing, slicing, try/except, etc.) and it’s just lost on me. I’m becoming unmotivated and feel very stupid. I’m still plugging away at it, but man, it’s tough.


Hello @sister. When you’re struggling with a task, it is always good to sit down, and think about what it is you’re exactly trying to achieve. Once you’ve figured that out, writing pseudo code really helps. Basically, imagine you are trying to write instructions for another person to do it. What would you tell them to do? Write that down. Then write it in a more code-like structure; using words such as loop through, or if…then. Finally, when you have that, it should be fairly easy to ‘translate’ that into code. See post number 3 by @thepitycoder.

I thought they were being really sneaky when you had to use int() to make it work. They taught us nothing about int() (or I couldnt remember)

I was like curse you codecademy! I cannot think of a way to solve this without dividing by 2, but dividing by 2 always turns it into float

10 minutes of trying to figure out alternate methods to dividing by 2

Dear google.

how do i convert float into int in python?

signed confused


Yeah. It was trash that was not taught. A leap is an understatement. This was irrelevant to the lesson work. I would not listen to the advice that says you should “sit down and think about it.” They should sit down and teach it.


Same here, #5 was super confusing. I had to bookmark it so I could get someone in real life who is a programmer to explain it to me. If you’re a completely new beginner, it’s a struggle.

Most of the lists and dicts and stuff were fine for me…but when it got to Classes section (Python Code Challenges: Classes), WOW it got hard. The hints didn’t help - looked at the answers and re-read the prompt…wondering who in the world wrote it because it answered the obvious while skipped the parts that was NOT taught in the Class section before. Also I found actual spelling typos (like so was spelled “se” etc.)

I did outside studying for Classes because Codecademy just failed at that topic…and thought I had a good grasp of it until that point.