#C13403. Simulated Filter Function

    ID: 42938 Type: Default 1000ms 256MiB

Simulated Filter Function

Simulated Filter Function

You are required to implement a function called my_filter which simulates the behavior of Python’s built-in filter function. This function takes a callable func and a list lst as input, and returns a new list containing only the elements of lst for which func returns True. The function should also validate the types of the inputs and raise a TypeError if func is not callable or if lst is not a list.

In this problem, your program will read from standard input two lines. The first line is a string indicating the filter condition, and the second line contains a space-separated list of integers. Based on the condition, apply the filter:

  • even: Keep even numbers, i.e. numbers where \( n \mod 2 = 0 \).
  • odd: Keep odd numbers, i.e. numbers where \( n \mod 2 \neq 0 \).
  • gt10: Keep numbers greater than 10.
  • all: Keep all numbers.
  • none: Remove all numbers (i.e. no number is retained).
Output the filtered list to standard output as space-separated integers on one line. If no numbers remain after filtering, output an empty line.

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line is a string representing the filter condition. It will be one of the following: even, odd, gt10, all, or none.
  2. The second line contains a space-separated list of integers. The list may be empty.

outputFormat

Output the filtered list to standard output (stdout) as a single line of space-separated integers. If the resulting list is empty, output an empty line.## sample

even
1 2 3 4 5 6
2 4 6