How do I change the class so that it can be tied up like Set {}?

Asked 2 weeks ago, Updated 2 weeks ago, 1 views

class Set:


    def __init__(self, my_list={}):
        self.my_list = my_list
        print(my_list)

How can I implement a class that when a=Set ([1,2,3,1]) comes out as {1,2,3} and is deduplicated?

python class

2022-09-20 15:16

1 Answers

class Set:
    def __init__(self, my_list:list):
        a = []
        for i in my_list:
            if i not in a:
                a.append(i)
        self.my_list = a
        print(self.my_list)


2022-09-20 15:16

If you have any answers or tips


© 2022 pinfo. All rights reserved.