# 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.

4 Likes

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.

3 Likes

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.

5 Likes

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
else:
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?

2 Likes

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.

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.

3 Likes

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

how do i convert float into int in python?

Thanks,
signed confused

2 Likes

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.

2 Likes

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.