Can someone describe what these functions do?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jcl43
    New Member
    • Nov 2008
    • 6

    #1

    Can someone describe what these functions do?

    Code:
    def swime(lst):
        p = lst[0]
        S = []
        B = []
        for x in lst:
            if x < p:
                S.append(x)
            else:
                B.append(x)
        return S + swerve(B)	
    
    def swerve(lst):
        result = []
        for x in lst:
            if x > 0:
                result.append(x)
        result.sort()
        return result
    With these two functions, I'm not really sure what the first one does ? Can anyone explain it to me ? I understand the swerve function but not the swime one 0.o
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    it's the same as swerve() only it uses the first element of lst as treshold instead of 0.

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      It appears that swime() may be the primary function. It breaks up a list into two lists (S and B), S with items that evaluate less than list element 0 and B with list element 0 and the others that evaluate greater than list element 0. It then returns the sum of S and the list returned by swerve(B).

      BV

      Comment

      Working...