Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
AbstractFamily.{keys,values,items}: New
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Aug 23, 2022
1 parent 12be2d9 commit 78400bc
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/sage/sets/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 78400bc

Please sign in to comment.