catower
Split this topic
54
A post was merged into an existing topic: What does index of lst even mean?
catower
Split this topic
55
2 posts were merged into an existing topic: Solution Discussion for lists code challenge
catower
Split this topic
57
A post was merged into an existing topic: What does index of lst even mean?
catower
Split this topic
58
4 posts were merged into an existing topic: What does index of lst even mean?
catower
Split this topic
60
catower
Split this topic
64
8 posts were merged into an existing topic: What does index of lst even mean?
catower
Split this topic
76
2 posts were split to a new topic: Why does my code print none?
catower
Split this topic
78
2 posts were split to a new topic: I believe I found a solution?
catower
Split this topic
79
2 posts were split to a new topic: Is my solution valid?
catower
Split this topic
82
catower
Split this topic
84
2 posts were split to a new topic: Why do I need an iterable?
stetim94
Split this topic
86
5 posts were split to a new topic: Double index
catower
Split this topic
87
catower
Split this topic
88
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
catower
Split this topic
95
9 posts were merged into an existing topic: Solution Discussion for lists code challenge
stetim94
Split this topic
103
2 posts were split to a new topic: Challenge Lists -Double Index
stetim94
Split this topic
106
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)