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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Dijkstra algorithm helping find new space 1bumcheek 7 888 Jul-28-2023, 08:30 AM
Last Post: Gribouillis
  helping PyInstaller To Find files Harshil 0 1,441 Aug-30-2020, 10:16 AM
Last Post: Harshil
  Trying to understand classes menator01 7 3,196 Oct-27-2019, 04:26 PM
Last Post: menator01
  Help me understand this... (Classes and self). Ceegen 15 8,120 Mar-31-2019, 10:41 PM
Last Post: Yoriz
  Using classes? Can I just use classes to structure code? muteboy 5 4,978 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