Python: Matching Index values to List values -


having output of list of lists containing index values of grouped elements (somewhat) corresponding list of tuples, how combine them list of grouped tuples?

data=[(1, 1), (1.5, 2), (3, 4), (5, 7), (3.5, 5), (4.5, 5), (3.5, 4.5)] clusters=[[0], [], [4], [1, 2, 3, 5, 6]] 

these sample values/groups. example of i'm asking about:

coordinates= [[(1,1)], [], [(3.5,5)], [(1.5,2),(3,4),(5,7),(4.5,5),(3.5,4.5)]] 

i've tried list comprehensions , zips when comes getting value of [i] in clusters gets confusing.

i think two-level list comprehension want:

coordinates = [[data[index] index in cluster] cluster in clusters] 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -