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
10/17/2021 2:03:48 PM
Gopi Satya Sivakumar
4 Answers
New AnswerGopi 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
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