From 78400bcb1b3c2c90e5974904f8e554f455e3d72d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 15 Aug 2022 19:55:53 -0700 Subject: [PATCH] AbstractFamily.{keys,values,items}: New --- src/sage/sets/family.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/sage/sets/family.py b/src/sage/sets/family.py index 996eb106de6..0a597f28c03 100644 --- a/src/sage/sets/family.py +++ b/src/sage/sets/family.py @@ -431,6 +431,39 @@ def hidden_keys(self): """ return [] + @abstract_method + def keys(self): + """ + Return the keys of the family. + + EXAMPLES:: + + sage: f = Family({3: 'a', 4: 'b', 7: 'd'}) + sage: sorted(f.keys()) + [3, 4, 7] + """ + + @abstract_method(optional=True) + def values(self): + """ + Return the elements (values) of this family. + + EXAMPLES:: + + sage: f = Family(["c", "a", "b"], lambda x: x + x) + sage: sorted(f.values()) + ['aa', 'bb', 'cc'] + """ + + def items(self): + """ + Return an iterator for key-value pairs. + + A key can only appear once, but if the function is not injective, values may + appear multiple times. + """ + return zip(self.keys(), self.values()) + def zip(self, f, other, name=None): r""" Given two families with same index set `I` (and same hidden