FAQ: Code Challenge: Lists - Double Index

A post was merged into an existing topic: What does index of lst even mean?

2 posts were merged into an existing topic: Solution Discussion for lists code challenge

A post was merged into an existing topic: What does index of lst even mean?

4 posts were merged into an existing topic: What does index of lst even mean?

A post was merged into an existing topic: Solution Discussion for lists code challenge

8 posts were merged into an existing topic: What does index of lst even mean?

2 posts were split to a new topic: Why does my code print none?

2 posts were split to a new topic: I believe I found a solution?

2 posts were split to a new topic: Is my solution valid?

2 posts were split to a new topic: Why does my code omit a number from the list?

2 posts were split to a new topic: Why do I need an iterable?

5 posts were split to a new topic: Double index

A post was merged into an existing topic: Solution Discussion for lists code challenge

6 posts were split to a new topic: Index replacement isn’t accepted?

OHHHHHHHHHHHHHHHHHHHHHHH

lst is lst as in L S T, like “last,” not 1st as in 1 S T, like “first.”

Well, that was the FIRST stupid frustration.

2 Likes

9 posts were merged into an existing topic: Solution Discussion for lists code challenge

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

2 posts were split to a new topic: Code challenge: Lists - Double Index, index error

Getting a prompt saying " Make sure to define what should happen if index is too big!"
Is this a bug?
Can someone tell me why my code is not valid?

def double_index(lst, index):
if len(lst) < index:
return lst
else:
new_lst = lst[0:index]
new_lst.append(lst[index]*2)
new_lst = new_lst + lst[index+1:]
return new_lst

print(double_index([3, 8, -10, 12], 2))

You missed a corner case. what if you do:

print(double_index([3, 8, -10, 12], 4))

this condition is now false:

if len(lst) < index:

given 4 (index) isn’t larger then 4 (length of list), but the highest index is 3 (given lists are zero-indexed based)