human
What is a the Python code you requested given the following:
I am working on the file "Python/Python Morsels/uniques_only/my_try/uniques_only.ipynb".
The first task is:
Bonus2: allow your uniques_only function to work with unhashable objects
Can you write Python code for it?
assistant
#Here is the Python code you requested.

list(uniques_only([['a', 'b'], ['a', 'c'], ['a', 'b']]))

def uniques_only(iterable):
    """
    Function that accepts an iterable and returns a new iterable 
    with all items from the original iterable except for duplicates.
    """
    uniques_dict = {}
    
    for item in iterable:
        item = tuple(item) 
        if item not in uniques_dict:
            uniques_dict[item] = 1
            yield item

list(uniques_only([['a', 'b'], ['a', 'c'], ['a', 'b']]))

list(uniques_only([1, 2, 2, 1, 1, 3, 2, 1]))

def uniques_only(iterable):
    """
    Function that accepts an iterable and returns a new iterable 
    with all items from the original iterable except for duplicates.
    """
    uniques_dict = {}
    
    for item in iterable:
        try:
            hashed = tuple(item)
        except TypeError:
            hashed = item
            
        if hashed not in uniques_dict:
            uniques_dict[hashed] = 1
            yield item

list(uniques_only([1, 2, 2, 1, 1, 3, 2, 1]))

nums = [1, -3, 2, 3, -1]
squares = (n**2 for n in nums)

list(uniques_only(squares))

list(uniques_only([['a', 'b'], ['a', 'c'], ['a', 'b']]))

from timeit import default_timer
import unittest

class UniquesOnlyTests(unittest.TestCase):

    """Tests for uniques_only."""

    def assertIterableEqual(self, iterable1, iterable2):
        self.assertEqual(list(iterable1), list(iterable2))

    def test_no_duplicates(self):
        self.assertIterableEqual(uniques_only([1, 2, 3]), [1, 2, 3])

    def test_adjacent_duplicates(self):
        self.assertIterableEqual(uniques_only([1, 1, 2, 2, 3]), [1, 2, 3])

    def test_non_adjacent_duplicates(self):
        self.assertIterableEqual(uniques_only([1, 2, 3, 1, 2]), [1, 2, 3])

    def test_lots_of_duplicates(self):
        self.assertIterableEqual(uniques_only([1, 2, 2, 1, 1, 2, 1]), [1, 2])

    def test_accepts_iterator(self):
        nums = (n**2 for n in [1, 2, 3])
        self.assertIterableEqual(uniques_only(nums), [1, 4, 9])

    # To test the Bonus part of this...