Update update method

This commit is contained in:
Madhav Agarwal 2024-03-31 01:53:28 +05:30 committed by GitHub
parent cb15db1f0e
commit 8a841eb457
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -16,8 +16,16 @@ class set:
def clear(self):
self._a.clear()
def update(self, other):
for elem in other:
def update(self, other):
if isinstance(other, set):
self._a.update({elem: None for elem in other})
else:
try:
iterable = iter(other)
except TypeError:
raise TypeError("Input must be an iterable")
for elem in iterable:
self.add(elem)
def __len__(self):
@ -77,4 +85,4 @@ class set:
return '{'+ ', '.join([repr(i) for i in self._a.keys()]) + '}'
def __iter__(self):
return iter(self._a.keys())
return iter(self._a.keys())