What does index of lst even mean?

No one should be mad at you at all. You are doing exceptionally well to help the students. Most are frustrated with the method codeacademy uses. I honestly think what we are going through in this lesson can be avoided. You will realize that you go through the stress of explaining over and over again. Trust me and for fact, not all student will read all comments here. So, you might continue to get questions you have already answered. Again mtf, you have been exceptional and we can do better here. If most are complaining and yet there is nothing from codeacademy to effect some corrections, then it seems strange

2 Likes

Hello @sodiqolabodeafolayan.

I doubt there is a lesson that specifically covers doubling an element at a specific index in a list, but you presumably have learned about lists before encountering this challenge. Accessing an element of a list by its index should be familiar to you. All this challenge is asking us to do, is locate the element at the index specified by the index parameter, and double its value.

As to the Codecademy solution, it builds a new list in three parts. First it takes a slice of the original list up to the specified index, then it appends the doubled value of the element at the specified index, then it uses + to concatenate the slice of the original list from right after the specified index through the end of the list.

    new_lst = lst[0:index] #slice of the beginning of the list up to the index specified
    new_lst.append(lst[index]*2) #append the doubled value of the element at the specified index
    new_lst = new_lst + lst[index+1:] #concatenate the remaining elements from the original list
    return new_lst #return the new list

In the code you posted, the list has 4 elements. That means len(lst) is 4, but the index values are 0, 1, 2, 3. There is no element at index 4, so if the index is greater than or equal to the length of the list, we return the original list.

Thank you for the explanation.

2 Likes

What I find odd is that if index is a gray area of understanding, then list slicing would be even more cryptic. There is some incongruency, here.

I’ve mentioned in the past that the issue may stem from the name of the function…

double_index

This implies that it is the INDEX that is doubled, not the value AT that index.

double_value_at_index

would be less ambiguous.

As far as this problem having gotten any review, such as confirming that list indices, accessing values by index and mutating a list by accessing, changing, and replacing values, as well as other list operations are well explained, I can neither confirm nor deny said review.

Until such time as said review/revision takes place we are left to deal with each learner in turn, and try to suss out what they do understand, and what not. Yes, it means answering the same question multiple times, but that is my choice. I could just pass the question over and leave the learner to keep digging.

2 Likes

mtf, you are an absolute gem. A big hug. I have learnt patience and the willingness to always want to give helping hand. At this stage i have a fair understanding of the concept but i wont leave until i am 100% satisfied.

Thank you mtf and all the codeacademy team

2 Likes

Thank you so much for actually going line by line through the solution. I have read all the comments/replies here and was no further ahead in understanding what the code in the solution was actually doing. I was frustrated that I was not grasping it. Even putting the code through the visual python utility (http://pythontutor.com/visualize.html#mode=display) did not assist my understanding.

Your explanation is what I needed, so many thanks!

1 Like

Nope, you did not miss anything. There is a flaw in the course progression.

8 posts were split to a new topic: Code Challenge: Lists - Double Index

Well that explains the problem. None of that was taught to me in the class. I quadruple checked all of my notes (which are really shadow copies of EVERYTHING that I’ve been taught) - not one piece of that info was in there.

Referring this to @lilybird for further investigation.

1 Like

def double_index(lst, index):
if index >= len(lst):
return lst
else:
lst[index] *= 2
return lst

I have solved this challenge with the code above. However, I have a question regarding the code.

  1. if index >= len(lst):

Why is the assignment operator >= ? Python is xero-indexed, but I do not understand what is being executed.

Because if the index is not less than the length, it is out of range. That means equal or greater.

Wow, thank you for responding so quickly! Sorry about my late response, I was at my grandparents for the Thanksgiving Break and grandma bans electronics. I understand this concept now.

1 Like

Who would argue with Gran? The vittles are more than enough reward!

I’ve created a ticket for our Curriculum Team to audit this code challenge. I will report back here once I get an update. Thanks for flagging the issue.

4 Likes

I just want to add that CodeAcademy jumps around in their curriculum when a person subscribes to a certain track like “Computer Science,” rather than if a person had selected Python as their one track. As someone who is a beginner to CS and Python, I think this selection of problems is a little advanced. There was definitely a learning curve spike from the last project I was working on, and it doesn’t help that the prompt is confusing and hard to follow.

2 Likes

glad you felt like that . Ive been doing this for 5 weeks as a total newbie and find it very confusing … think i will have to pick it to pieces

There’s no lesson on assigning to a particular index in a list prior to this challenge. I’m doing the Analysing Financial Data with Python path and can vouch the same. You posted a link to selecting from a particular index above - not assignment.

This thread proves introducing it first in a challenge with no examples throws people off, sometimes causing them to give up coding for weeks. Especially considering that by this point, we’ve gained complete trust in the fact that everything is excellently explained on Codecademy before we’re expected to apply for ourselves in a challenge.

1 Like

I was on the same page as you for this one. I am still a little confused. I guess we need to use an IF statement to see if the lst == index?

I agree with you on this one. I also believe some things such as .zip and .append need to be practiced more thoroughly. They threw one lesson for each in there and expect us to do a project now and use them without enough practice?