I want to insert multiple tuples into a set which each tuple contains a list
and a string
.
Each tuple looks like:
sample_tuple = (['list of elements'], 'one_string')
If we check the type of sample_tuple
, we can be sure that it is a tuple
with 2 elements (one list and one string).
But when I use the "add" method to insert this tuple to my set, I get the error:
TypeError Traceback (most recent call last)
c:\run.ipynb Cell 47 in <cell line: 15>()
11 sample_tuple = (['list of elements'], 'one_string')
12 sample_set.add(sample_tuple)
TypeError: unhashable type: 'list'
But this is the way that I insert a tuple
into a set
in python.
Is there a way I can keep the form of my tuple
(ie my tuple
still consists of a list
and a string
) and then be able to insert this tuple into a set
in Python?