File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,7 +25,13 @@ def __init__(self):
2525
2626 def __repr__ (self ):
2727 """Return a string representation of the Components instance."""
28- return repr (self ._components )
28+ components_str = "\n " .join (
29+ [
30+ f"\t Component: { str (c .component ):80} Position: { c .position :>6.3f} "
31+ for c in self ._components
32+ ]
33+ )
34+ return f"Components:\n { components_str } "
2935
3036 def __len__ (self ):
3137 """Return the number of components in the list of components."""
@@ -155,3 +161,19 @@ def clear(self):
155161 None
156162 """
157163 self ._components .clear ()
164+
165+ def sort_by_position (self , reverse = False ):
166+ """Sort the list of components by position.
167+
168+ Parameters
169+ ----------
170+ reverse : bool
171+ If True, sort in descending order. If False, sort in ascending
172+ order.
173+
174+ Returns
175+ -------
176+ None
177+ """
178+ self ._components .sort (key = lambda x : x .position , reverse = reverse )
179+ return None
You can’t perform that action at this time.
0 commit comments