Reputation: 645
I have the following statement in a python routine:
return [hulls[h][i] for h, i in hull]
And I can't figure out what it does actually return.
I mean, hulls is a list of hull, so 'hulls[n]' is of type 'hull'. Additionally, hull is of type 'Point' hull is a list of points, but
for h, i in hull?
The docs don't mention why and how you can perform such a call, and it smells like some sort of list comprehension call, but I still can't read that syntax properly.
So I'd like help in understanding how you can translate the sentence in pseudocode, or c#
Thanks a lot.
Upvotes: 0
Views: 229
Reputation: 539
Yes, David is correct. If you're still confused about the line for h, i in hull: I think it means that hull is a list of tuples that have multiple elements. So you're using every element in hull to use as indices for hulls.
Upvotes: 0
Reputation: 11
Hulls looks to be a two dimensional array of things. Hull is a list of pairs of ints (x,y). For each coordinate in Hull, it returns the item in hulls in that place.
Upvotes: 1
Reputation: 18111
Yes, it is list comprehension. Your return statement could be rewritten less compactly as:
result = []
for h, i in hull:
result.append(hulls[h][i])
return result
Upvotes: 3