Reputation: 191
I have a set of code that takes a list full of simple objects and iterates through the objects and compares them to each other. The list is 30 objects long and the objects have 8 class members.
def createSijkTest(data):
Sijk = np.empty(getDimensions(data))
x = 0
for item0 in data:
y = 0
for item1 in data:
z = 0
while z < 8:
member0 = item0.__dict__.items()
member1 = item1.__dict__.items()
if member0[z] == member1[z]:
Sijk[x,y,z] = 1
else:
Sijk[x,y,z] = 0
z += 1
y += 1
x += 1
The output should be a numpy array of 30x30x8 dimensions. I get an error: TypeError: 'dict_items' object does not support indexing. I understand why I get the error, but I don't know how to fix it.
The code for the objects is:
class row:
def __init__(self, L):
self.dDate = []
self.name = []
self.dType = []
self.city = []
self.state = []
self.rCommittee = []
self.employer = []
self.amount = []
self.dDate.append(L[0])
self.dType.append(L[1])
self.name.append(L[2])
self.city.append(L[3])
self.state.append(L[4])
self.rCommittee.append(L[5])
self.employer.append(L[6])
self.amount.append(float(L[7]))
Upvotes: 1
Views: 80
Reputation: 22340
the most direct thing you can try is converting it to list:
list(item0.__dict__.items())
Upvotes: 2