mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-09 21:20:17 +00:00
Update update method
This commit is contained in:
parent
cb15db1f0e
commit
8a841eb457
@ -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())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user