reduce number of lines slightly by using yield from filter(match, ...)
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 10 Jun 2023 22:50:03 +0000 (23:50 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 10 Jun 2023 22:50:03 +0000 (23:50 +0100)
src/openpower/insndb/core.py

index 21f5cc482a68b8c48dbfbae340a373ee7442a442..d19f92a5622059b42710dd16089542d25855db20 100644 (file)
@@ -108,9 +108,8 @@ class Tuple(Node, tuple):
         if isinstance(clsself, type):
             yield ("[]", clsself.__datatype)
         else:
-            for (index, item) in enumerate(clsself):
-                if match(item):
-                    yield (str(index), item)
+            for (index, item) in enumerate(filter(match, clsself)):
+                yield (str(index), item)
 
 
 class Dict(Node, dict):
@@ -144,9 +143,7 @@ class Dict(Node, dict):
         if isinstance(clsself, type):
             yield ("{}", clsself.__datatype)
         else:
-            for (key, value) in clsself.items():
-                if match(value):
-                    yield (key, value)
+            yield from filter(lambda kv: match(kv[0]), clsself.items())
 
 
 class VisitorMethod: