diff --git a/python/_set.py b/python/_set.py index fc3bf33e..2ca645fa 100644 --- a/python/_set.py +++ b/python/_set.py @@ -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()) \ No newline at end of file + return iter(self._a.keys())