Get unique items from an iterable while maintaining item order
See if you can figure out at least one of the bonuses for this exercise if you have time.
I want you to write a function that accepts an iterable and returns a new iterable with all items from the original iterable except for duplicates.
Here's an example:
>>> uniques_only([1, 2, 2, 1, 1, 3, 2, 1])
[1, 2, 3]
>>> nums = [1, -3, 2, 3, -1]
>>> squares = (n**2 for n in nums)
>>> uniques_only(squares)
[1, 9, 4]
Note that the order of the returned elements should remain the same.
Bonus 1
This is just a preview of the problem statement.
This exercise includes 3 bonuses and 10 hint links.
To solve this exercise, sign in to your Python Morsels account.
My name is Trey Hunner and I hold Python trainings for teams. I've spent countless hours refining my most interesting Python exercises into Python Morsels, a Python skill-building platform for folks who already know Python. Python Morsels is design to help you deepen your Python skills every week.
Sign up for Python Morsels to access this exercise and many more.
Join Python Morsels ✨