<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def traverse(self, attr_name = None, attr_value = None):
 """traverse the whole sprite tree and return child sprites which have the attribute and it's set to the specified value. If falue is None, will return all sprites that have the attribute """

        for sprite in self.sprites:
            if (attr_name is None) or \
               (attr_value is None and hasattr(sprite, attr_name)) or \
               (attr_value is not None and getattr(sprite, attr_name, None) == attr_value):
                yield sprite

            for child in sprite.traverse(attr_name, attr_value):
                yield child