We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Remove Non-Integers

The built-in type() function can be used to get the type of a variable. For example:

type(1) is int
# True

type("1") is str
# True

type(1.0) == float
# True

type("seventy-six") == int
# False

Assignment

Complete the remove_nonints() function. It takes a list and returns a new list but with all the non-integer types removed.

new_list: list[int] = remove_nonints(["1", 1, "3", "400", 4, 500])
print(new_list)
# [1, 4, 500]

Do not change the input nums list. Return a new list with only the integers.