Ok that was simple change. Dont know why but there was a small error preventing that from working before. But the problem is with the creating findsurrounding function
On Tue, Apr 17, 2012 at 3:14 PM, Alan Gauld <alan.ga...@btinternet.com>wrote: > On 17/04/12 19:23, leo degon wrote: > >> Ok so I've done a bit of work on the program and rewrote it. I tried to >> take everyones advice. I've used more functions, I've made it so that it >> is a list of lists each containing an integer instead of another list >> with a single entry. >> > > It still looks too complicated to me. > > > #set intital distribution >> >> if initial=='r': >> for i in range(x): >> for j in range(y): >> space[i].__setitem__(j,random.**randint(0,1)) >> > > What's with the __setitem__ stuff? You should never normally need to call > that directly. I would expect something like > > > for i in range(x): > for j in range(y): > space[i][j] = randint(0,1) > > Or, using list comprehensions: > > for i in range(x): > space[i] = [randint(0,1) for j in range(y)] > > Or even: > > space = [[randint(0,1) for j in range(y)] for i in range(x)] > > > Which, for x,y = 3,4 gives a structure like: > > >>> space > [[1, 0, 0, 0], [1, 0, 1, 1], [0, 1, 1, 0]] > > >>> > > > elif initial=='c': >> for i in range(x): >> for j in range(y): >> if (i+j)%2==0: >> space[i].__setitem__(j,1) >> > > Again I'd just use > > space[i][j] = 1 > > HTH > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > > ______________________________**_________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor> >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor