[Tutor] Question about lists
Leo Degon
existentialleo at gmail.com
Fri Sep 21 15:31:53 CEST 2012
I'm trying to create a class where the main focus is creating a list whose
elements are lists and the elements of those lists are collection of zeros
and ones. I am trying to create functions to rotate the list ninety
degrees, to reflect it. Having a few problems with the rotation.
get TypeError: 'list' object is not callable
def pset(n):
for i in n:
print(i)
class board():
def make(self,size):
b=[]
for i in range(size[0]):
b.append([])
for j in range(size[1]):
b[i].append(0)
return b
def rotate(self,board,size):
size[0],size[1]=size[1],size[0]
new=board(size)
lists=[]
for j in range(size[1]):
lists.append([])
for i in range(size[0]).__reversed__():
lists[j].append(board[i][j])
for i in range(size[1]):
for j in range(size[0]):
new.board[i,j]=lists[i,j]
return(new.board)
def __init__(self,size):
self.size=size
self.board=self.make(size)
y=[7,7]
x=board(y)
pset(x.board)
x.board[0][0]=1
print()
pset(x.board)
print()
x.board=x.rotate(x.board,x.size)
pset(x.board)
print()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120921/2bc7596a/attachment.html>
More information about the Tutor
mailing list