-1

How do we remove duplicates from an iterator and put it in sorted order?

Sample input:

it = iter(["black", "aqua", "aqua", "black", "black", "blue", "aqua", "blue", "fuchsia", "gray", "gray", "green", "green", "aqua", "lime", "lime"])  

Expected output:

it = iter(["aqua", "black", "blue", "fuchsia", "gray", "green", "lime",])  

Similar questions have been asked before:

There are almost no restrictions on this question other than it be written in Python.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Toothpick Anemone
  • 4,290
  • 2
  • 20
  • 42

1 Answers1

0
# oit ..... output iterator
# iit ..... input iterator  
oit = sorted(set(iit))    
Toothpick Anemone
  • 4,290
  • 2
  • 20
  • 42
  • 2
    `oit` is a list, not an iterator. You'll need to wrap it in `iter` if you want an iterator i.e. `oit = iter(sorted(set(iit)))` – Nick Apr 23 '23 at 01:37