User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 391,974 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,171 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser:

Special sort a list

Join Date: Dec 2006
Posts: 384
Reputation: woooee is on a distinguished road 
Rep Power: 2
Solved Threads: 52
woooee woooee is offline Offline
Posting Whiz

Re: Special sort a list

  #4  
May 9th, 2008
Some modifications to your code. First you have to test for zero, and second, the variable "b" is not necessary as you can just use len(x). Hopefully this is what you want to do.
def kopi(x):
    y = []
    for num in x:
        new_num = num - 1
        if new_num < 0:
           new_num=0
        print new_num,
        y.append(new_num)
    y.append (len(x))
    print len(x)
    print "new list inside function", y
    return y

##   15 iterations
if __name__ == "__main__":
   x=[4,4,2]
   print "the beginning list is", x
   for k in range(0, 15):
      x=kopi(x)
      print "the list is now", x, "\n"    
Last edited by woooee : May 9th, 2008 at 10:52 am.
Reply With Quote  
All times are GMT -4. The time now is 9:28 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC