Problem C
Remove Odds
Write two functions for removing odd numbers from integer lists:
-
extract_evens(int_list):
Returns a new list with only even integers from int_list, without modifying int_list. -
remove_odds(int_list):
Removes odd integers from int_list, thus modifying int_list.
Hint: Functions have the ability to modify mutable objects in the calling program. Lists are mutable objects.
The main file, which handles input and output, is already provided. - Please only submit your function definitions, without any code outside the functions!
Input
Each of the functions should accept one list
In the samples below, the input consists of one line
containing a sequence
In the tests,
Output
The function extract_evens()
should return a new list
The function remove_odds() should
return nothing (just None), but
should modify the given list
In each test case, the autograder will call both of the functions with the given list as a parameter, in sequence, and will verify the results as well as the effects on the given list, and print the following four lines to the output, as seen in the samples below:
-
“Original list before calling functions: {
}” -
“Resulting list after extracting evens: {
}” -
“Original list after extracting evens and before removing odds: {
}” -
“Original list after removing odds: {
}”
Sample Input 1 | Sample Output 1 |
---|---|
1 1 2 3 4 5 |
Original list before calling functions: [1, 1, 2, 3, 4, 5] Resulting list after extracting evens: [2, 4] Original list after extracting evens and before removing odds: [1, 1, 2, 3, 4, 5] Original list after removing odds: [2, 4] |
Sample Input 2 | Sample Output 2 |
---|---|
10 7 7 7 7 1 10 9 9 |
Original list before calling functions: [10, 7, 7, 7, 7, 1, 10, 9, 9] Resulting list after extracting evens: [10, 10] Original list after extracting evens and before removing odds: [10, 7, 7, 7, 7, 1, 10, 9, 9] Original list after removing odds: [10, 10] |
Sample Input 3 | Sample Output 3 |
---|---|
1 1 2 3 4 5 6 7 8 9 10 |
Original list before calling functions: [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Resulting list after extracting evens: [2, 4, 6, 8, 10] Original list after extracting evens and before removing odds: [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Original list after removing odds: [2, 4, 6, 8, 10] |
Sample Input 4 | Sample Output 4 |
---|---|
9 1 3 3 52 7 |
Original list before calling functions: [9, 1, 3, 3, 52, 7] Resulting list after extracting evens: [52] Original list after extracting evens and before removing odds: [9, 1, 3, 3, 52, 7] Original list after removing odds: [52] |