Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Helping understand classes
#11
(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
99 percent of computer problems exists between chair and keyboard.
Reply


Messages In This Thread
Helping understand classes - by Miraclefruit - Nov-26-2017, 03:54 AM
RE: Helping understand classes - by heiner55 - Nov-26-2017, 04:41 AM
RE: Helping understand classes - by buran - Nov-26-2017, 09:47 AM
RE: Helping understand classes - by heiner55 - Nov-26-2017, 10:58 AM
RE: Helping understand classes - by Windspar - Nov-26-2017, 10:51 PM
RE: Helping understand classes - by Miraclefruit - Nov-27-2017, 01:31 AM
RE: Helping understand classes - by Larz60+ - Nov-27-2017, 01:43 AM
RE: Helping understand classes - by Miraclefruit - Nov-27-2017, 02:15 AM
RE: Helping understand classes - by Windspar - Nov-27-2017, 02:15 AM
RE: Helping understand classes - by Windspar - Nov-27-2017, 01:58 PM
RE: Helping understand classes - by heiner55 - Nov-27-2017, 05:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Dijkstra algorithm helping find new space 1bumcheek 7 980 Jul-28-2023, 08:30 AM
Last Post: Gribouillis
  helping PyInstaller To Find files Harshil 0 1,490 Aug-30-2020, 10:16 AM
Last Post: Harshil
  Trying to understand classes menator01 7 3,298 Oct-27-2019, 04:26 PM
Last Post: menator01
  Help me understand this... (Classes and self). Ceegen 15 8,258 Mar-31-2019, 10:41 PM
Last Post: Yoriz
  Using classes? Can I just use classes to structure code? muteboy 5 5,076 Nov-01-2017, 04:20 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020