@@ -624,7 +624,7 @@ def __init__(self, default=None):
624
624
625
625
def __call__ (self ):
626
626
"""Return the current element, or None."""
627
- if not len ( self ._elements ) :
627
+ if not self ._elements :
628
628
return self ._default
629
629
else :
630
630
return self ._elements [self ._pos ]
@@ -662,7 +662,7 @@ def home(self):
662
662
663
663
The first element is returned.
664
664
"""
665
- if not len ( self ._elements ) :
665
+ if not self ._elements :
666
666
return
667
667
self .push (self ._elements [0 ])
668
668
return self ()
@@ -678,33 +678,43 @@ def clear(self):
678
678
679
679
def bubble (self , o ):
680
680
"""
681
- Raise *o* to the top of the stack. *o* must be present in the stack .
681
+ Raise all references of *o* to the top of the stack, and return it .
682
682
683
- *o* is returned.
683
+ Raises
684
+ ------
685
+ ValueError
686
+ If *o* is not in the stack.
684
687
"""
685
688
if o not in self ._elements :
686
- raise ValueError ('Unknown element o ' )
687
- old = self ._elements [:]
689
+ raise ValueError ('Given element not contained in the stack ' )
690
+ old_elements = self ._elements . copy ()
688
691
self .clear ()
689
- bubbles = []
690
- for thiso in old :
691
- if thiso == o :
692
- bubbles .append (thiso )
692
+ top_elements = []
693
+ for elem in old_elements :
694
+ if elem == o :
695
+ top_elements .append (elem )
693
696
else :
694
- self .push (thiso )
695
- for _ in bubbles :
697
+ self .push (elem )
698
+ for _ in top_elements :
696
699
self .push (o )
697
700
return o
698
701
699
702
def remove (self , o ):
700
- """Remove *o* from the stack."""
703
+ """
704
+ Remove *o* from the stack.
705
+
706
+ Raises
707
+ ------
708
+ ValueError
709
+ If *o* is not in the stack.
710
+ """
701
711
if o not in self ._elements :
702
- raise ValueError ('Unknown element o ' )
703
- old = self ._elements [:]
712
+ raise ValueError ('Given element not contained in the stack ' )
713
+ old_elements = self ._elements . copy ()
704
714
self .clear ()
705
- for thiso in old :
706
- if thiso != o :
707
- self .push (thiso )
715
+ for elem in old_elements :
716
+ if elem != o :
717
+ self .push (elem )
708
718
709
719
710
720
def report_memory (i = 0 ): # argument may go away
0 commit comments