I am trying to clean up some code that contains some rather long and ugly if/else statements and I wanted to get the opinon of the community on the what is considered to be the most elegant approach.
Would the following be acccpetable or might there be a more Pythonic, or succint syntax? Any and all opinions on the matter is greatly appreciated!
Here's a snippet:
def __add__(self, other):
conditions = [
index in self.items,
self.output[i] not in self.values
]
if isinstance(other, (list, tuple, set)):
for index in other:
if all(conditions):
self.__add_items__(index)
self.values.add(self.output[i])
conditions = [
other in self.items,
self.output not in self.values
]
if all(conditions):
self.__add_items__(other)
self.values.add(self.output[other])
Aucun commentaire:
Enregistrer un commentaire