Fix: TypeError: unhashable type: slice

Example Code:
data_list = [slice(1, 2), slice(3, 4)]
data_set = set(data_list)
Error:
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[92], line 2
      1 data_list = [slice(1, 5), slice(5, 10)]
----> 2 data_set = set(data_list)

TypeError: unhashable type: 'slice'

    Reason for the Error:

    Here we are trying to convert a list of slices to a set, this is not possible because slices are mutable whereas sets are a hash-based data structure that needs their elements to be immutable.

TypeError- unhashable type- slice

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!