1

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]))
2
  • self.dDate = [L[0]], etc, is a lot simpler and easy to read. Commented Feb 6, 2016 at 20:26
  • you have z += 1 nested 1 more level, right? Commented Feb 6, 2016 at 20:28

1 Answer 1

2

the most direct thing you can try is converting it to list:

list(item0.__dict__.items())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.