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

@ -17,7 +17,15 @@ class set:
self._a.clear() self._a.clear()
def update(self, other): def update(self, other):
for elem in 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) self.add(elem)
def __len__(self): def __len__(self):