0
Delete a slice
Dwight has given you a list with some integers. In this list, there is a bad series. The bad series starts from the beginning and spans up till the A[0]th index. Example: for [1,0,4,7] the bad series is [1,0] spanning up till 1st index Therefore, the desired list is [4, 7] for [2,1,5,8,9], the bad series is [2,1,5] spanning up till the 2nd index Therefor, the desired list is [8,9] Complete the given method solve which takes as parameter a list A and returns A such that the bad series is removed
6 Antworten
+ 6
Gopi Satya Sivakumar ,
can you show us your attempt please?
+ 3
I don’t get it how do u know the bad series?
+ 3
Gopi Satya Sivakumar ,
if understand you correctly, it can be done like
# these are the lists mentioned:
lst = [2,1,5,8,9]
bad = [2,1,5]
▪︎use a for loop and iterate through the 'bad' list
▪︎use each number you get there, and remove it in the 'lst' list
▪︎print the 'lst' list
the result is: [8, 9]
this is just 3 lines of code
0
I Did Like This And Got Only Two Cases Passed.Another Test Case Didn't Pass.How Will It Can Be Passed?
def solve(A):
n = A[0]
if(len(A) % 2 == 0):
del A[:n+1]
return A
else:
A = A[-n:]
return A
0
2nd test case worng
0
def solve(A):
# write your code here
n=len(A)
i=A[0]
if n%2==0:
del A[:i+1]
else:
A=A[1+i:]
return A