Python Forum

Full Version: Helping understand classes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(Nov-27-2017, 02:15 AM)Windspar Wrote: [ -> ]Really Mit quiz courseware. I thought they be harder.
Just walk through the code.

def reorder(L):
    for e in L:  #e will be Square then  Rectangle, and finally a Circle
        if e < L[0]:  # e always compares to Square. You are compare __lt__ overload.
            # round 1 Square < Square = False
            # round 2 Rectangle < Square = True
            # round 3 Circle < Square = False

            L[0] = e # Square get Replace by Rectangle

Made an error in walk through.

def reorder(L):
    for e in L:  #e will be Square then  Rectangle, and finally a Circle
        if e < L[0]:  # e always compares to L[0]. You are compare __lt__ overload.
            # round 1 Square < Square = False
            # round 2 Rectangle < Square = True , changes L[0] = Rectangle
            # round 3 Circle < Rectangle = False

            # The danger changing list in a loop
            L[0] = e # Square get Replace by Rectangle
Pages: 1 2