Ask if python can compose a set of content into one element and insert it into the collection.

for example, there is data
("Alex",13), (" Bob",12), which is the element of name and age, respectively

it is hoped that such a data can be stuffed into the set as an element, so that data such as ("Alex",13) can be automatically deduplicated next time.
can also maintain a specific format after it is removed.

At present, it seems that the only way to consider

is to change such data into a string like "Alex:13", then
takes it out and splits the class on its own.

There seems to be a better way to see it on

Fluent Python, but I can"t find it anywhere at the moment.

ask for advice. Is there any good way?

Mar.03,2021

named_tuple should be able


maybe I don't have a thorough understanding of the subject.
isn't this a simple operation on a collection?

>>> s = set((('Alex', 13), ('Bob', 12))) -sharp 
>>> s
{('Bob', 12), ('Alex', 13)} 
>>> s.add(('Alex', 13)) -sharp 
>>> s
{('Bob', 12), ('Alex', 13)} -sharp 
>>> s
{('Bob', 12), ('Alex', 13)}
>>> s.add(('Alex', 11)) -sharp 
>>> s
{('Bob', 12), ('Alex', 11), ('Alex', 13)} -sharp 
>>>

my tm is stupid. I used to write a dictionary, but the dictionary failed. Just name the tuple directly and get it done

Menu