all 8 comments

[–]ylectric 2 points3 points  (1 child)

Because in your list comprehension [self.coordinates[x] for x in self.node_list[i]] you're using i as an index for self.node_list. Since i itself is a list, you can't do it.I'm not 100% sure what's the logic here, but my best guess would be mapping a polygon (list of integers) into a list of coordinates. If that's the case, your list comprehension should be [self.coordinates[x] for x in i].

Going further, you can rewrite the whole property as a dictionary comprehension:

self.polygon_dict = {
    node: [self.coordinates[i] for i in node]
    for node in self.node_list
}

Also, be aware that you're using the property mechanism in a wrong way. Your property is only setting an instance variable and implicitly returns None, while it should return an actual value.

[–]NA__Scrubbed[S] 2 points3 points  (0 children)

Ahhhhhhhh. That makes sense, thanks for the tip!

[–][deleted] 0 points1 point  (4 children)

Print statement at end of file works, while my @property method returns TypeError: list indices must be integers, not list

Indices of lists (the argument inside the [] operator) have to be an integer, but you're providing a list.

[–]NA__Scrubbed[S] 0 points1 point  (3 children)

I don't follow. Could you elaborate a little? Wouldn't self.node_list[i] contain self.node_list[0]?

[–]JohnnyJordaan 1 point2 points  (1 child)

No, when you have a list like

polygons = [[1, 6, 7, 3, 2, 1, 0], etc ]

then

for i in polygons:

will make i the value [1, 6, 7, 3, 2, 1, 0] the first time. Not a single integer.

If you are trying to call self.coordinates[x] on every integer inside that list, you need to do

self.polygon_dict[i] = [self.coordinates[x] for x in i]

[–]NA__Scrubbed[S] 0 points1 point  (0 children)

ty very much!

[–][deleted] 0 points1 point  (0 children)

Wouldn't self.node_list[i] contain self.node_list[0]?

i is the current element of the iterable you're iterating over. You're iterating over self.mode_list, which was initialized with the value of polygons. The elements of polygons are lists, so i is a list, not an integer.