Given a string S
and a list of indices X
, modify S
by removing the element at each index of S
while using that result as the new value of S
.
For example, given S = 'codegolf'
and X = [1, 4, 4, 0, 2]
,
0 1 2 3 4 5 6 7 |
c o d e g o l f | Remove 1
c d e g o l f | Remove 4
c d e g l f | Remove 4
c d e g f | Remove 0
d e g f | Remove 2
d e f
Your task is to perform this process, collect the values of S
after each operation, and display each on a newline in order. The final answer would be
S = 'codegolf'
X = [1, 4, 4, 0, 2]
Answer:
codegolf
cdegolf
cdeglf
cdegf
degf
def
- This is code-golf so make your code as short as possible.
- You may assume that the values in
X
are always valid indices forS
, and you may use either 0-based or 1-based indexing. - The string will only contain
[A-Za-z0-9]
- Either
S
orx
may by empty. IfS
is empty, it follows thatx
must also be empty. - You may also take
S
as a list of characters instead of a string. - You may either print the output or return a list of strings. Leading and trailing whitespace is acceptable. Any form of output is fine as long as it is easily readable.
Test Cases
S = 'abc', x = [0]
'abc'
'bc'
S = 'abc', x = []
'abc'
S = 'abc', x = [2, 0, 0]
'abc'
'ab'
'b'
''
S = '', x = []
''
S = 'codegolfing', x = [10, 9, 8, 3, 2, 1, 0]
'codegolfing'
'codegolfin'
'codegolfi'
'codegolf'
'codgolf'
'cogolf'
'cgolf'
'golf'
S
as a list of characters? \$\endgroup\$len(x)+1
strings. \$\endgroup\$