Carlos wrote: > Hello to all, > > Ok, after reading your comments I ended up with this: > > #Easy_2DCA_01.py > #A very basic 2D script that lets you play with Wolfram's rule 30 > > A_List = [0]*10+[1]+[0]*10 > A_Len = len(A_List) > B_List = [] > print A_List > Iterations = 5 > > rule_30 = { > (1, 1, 1) : 0, > (1, 1, 0) : 0, > (1, 0, 1) : 0, > (1, 0, 0) : 1, > (0, 1, 1) : 1, > (0, 1, 0) : 1, > (0, 0, 1) : 1, > (0, 0, 0) : 0, > } > > for j in range (Iterations): > for i in range (A_Len): > It seems to me you could just iterate on a range of A_Len-1 and then you wouldn't have to wrap around. Perhaps you need it to work that way, though. I'm not sure. > x = A_List[i-1] > y = A_List[i] > > if i < A_Len-1: > z = A_List[i+1] > > else: > z = A_List[0] Can just become x,y,z = A_List[i-1:i+1] + [A_List[(i+1) % A_Len]]
Though it's slightly less readable, it's also a bit shorter :) Alternately, you can leave your x and y definitions, and change the if/else stuff to z = A_List[(i+1) % A_Len] At least I think so :) HTH, -Luke _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor