Q:

Write a Python program to remove first specified number of elements from a given list satisfying a condition

0

Write a Python program to remove first specified number of elements from a given list satisfying a condition.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def condition_match(x):
    return ((x % 2) == 0)
def remove_items_con(data, N):
    ctr = 1
    result = []
    for x in data:
        if ctr > N or not condition_match(x):
            result.append(x)
        else:
            ctr = ctr + 1
    return result
nums = [3,10,4,7,5,7,8,3,3,4,5,9,3,4,9,8,5]
N = 4
print("Original list:")
print(nums)
print("\nRemove first 4 even numbers from the said list:")
print(remove_items_con(nums, N))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now