[Tutor] checking list position

Mauricio Villamil mvillamilb at gmail.com
Thu Oct 24 03:42:05 CEST 2013


Hello,

And thank you for any help.

I am writing a little prog. On this part I need to recursively (preferably)
 write to a list a value only if it's less than 49, else do an operation to
make it less than 49, then check which is the next available spot on the
list and write there ... so pseudo code would be like:

def getGM(seed): ## function

 Gnumbers = [5] ## list to write to
 for i in Gnumbers: iterate from begining of list to write to it
 if (result <= 49):

result = math.floor(seed   * 1.61803398875)     ## find value lesser than 49
place = int(len(Gnumbers))                             ## fins how long is
the list so far
Gnumbers[i] = result                                      ##  place result
at spot in list
print  ("this is place   :", place)                        ## see length of
list
 else: ## if number bigger than 49 then divide the number to make it
smaller and wrote
 result = math.floor(seed / 1.61803398875)  ## make number smaller
 if (result <= 49):## if right size write to array
 Gnumbers[i] = result
 else:
getGM(result)## if not divide again ( this could be a dedicated function ?


So ..the biggie is knowing all any time which is the next available place
in the list to write to (we don't want to overwirte previous values ....

Many thanks for suggestions !!


M.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131023/8f83ca14/attachment.html>


More information about the Tutor mailing list