- 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

28th May 2021, 10:58 PM
Ailana
Ailana - avatar
4 ответов
+ 1
U didn't delete any letter and the return must be out of loop.
29th May 2021, 4:54 AM
Oma Falk
Oma Falk - avatar
+ 1
Adding to Frogged Syntax error, correct syntax is list.index(element)
29th May 2021, 4:56 AM
Isaac Fernandes
Isaac Fernandes - avatar
+ 1
The pop method removes element from the list on the given index
29th May 2021, 5:10 AM
Eashan Morajkar
Eashan Morajkar - avatar
0
def last_survivor(letters, coords): for i in coords: letters.pop(i) return letters
29th May 2021, 5:09 AM
Eashan Morajkar
Eashan Morajkar - avatar