Back to Lesson

Safe Deduplication

Cleanse lists dynamically to form reliable baselines.

Instructions

  • Given
    inventory = ["apple", "pear", "apple", "banana", "pear", "orange"]
  • Create a tracking set (
    seen = set()
    ) and an output list (
    unique_inv = []
    ).
  • For each item, if it's not in
    seen
    , add it to both
    seen
    and
    unique_inv
    .
  • Print
    unique_inv
    to see the ordered deduction.
main.py
main.py