- 1
HELPPP
You are given a string of letters and an array of numbers. The numbers indicate positions of letters that must be removed, in order, starting from the beginning of the array. After each removal the size of the string decreases (there is no empty space). Return the only letter left. Here is my code: def last_survivor(letters, coords): for i in letters: return i.index[coords] What's wrong here???? explain plz
4 Answers
+ 1
U didn't delete any letter and the return must be out of loop.
+ 1
Adding to Frogged Syntax error, correct syntax is list.index(element)
+ 1
The pop method removes element from the list on the given index
0
def last_survivor(letters, coords):
for i in coords:
letters.pop(i)
return letters