By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,898 Members | 1,183 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,898 IT Pros & Developers. It's quick & easy.

Can someone describe what these functions do?

P: 6
Expand|Select|Wrap|Line Numbers
  1. def swime(lst):
  2.     p = lst[0]
  3.     S = []
  4.     B = []
  5.     for x in lst:
  6.         if x < p:
  7.             S.append(x)
  8.         else:
  9.             B.append(x)
  10.     return S + swerve(B)    
  11.  
  12. def swerve(lst):
  13.     result = []
  14.     for x in lst:
  15.         if x > 0:
  16.             result.append(x)
  17.     result.sort()
  18.     return result
  19.  
  20.  
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
Dec 10 '08 #1
Share this Question
Share on Google+
2 Replies


Dormilich
Expert Mod 5K+
P: 8,639
it's the same as swerve() only it uses the first element of lst as treshold instead of 0.
Dec 10 '08 #2

bvdet
Expert Mod 2.5K+
P: 2,851
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
Dec 10 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.