Back to Lesson

Data Type Filtering

Filter mixed list elements using isinstance() to safeguard processes.

Instructions

  • Given
    mixed = [42, "hello", 3.14, True, [1, 2], 55, "world"]
  • You want to retrieve only the integers, but
    True
    is a subclass of int! You must check if the type is exactly
    int
    or use
    isinstance
    and not a boolean.
  • Create a list containing only elements where
    type(item) is int
    . Print the sum of these integers using
    sum()
    .
main.py
main.py