python - multiple iteration of the same list -


i have 1 list of data follows:

from shapely.geometry import box  data = [box(1,2,3,4), box(4,5,6,7), box(1,2,3,4)] sublists = [a,b,c] 

the list 'data' has following sub-lists:

a = box(1,2,3,4) b = box(4,5,6,7) c = box(1,2,3,4) 

i have check if sub-lists intersect. if intersect should put in 1 tuple; , if not intersect should put in different tuple. expected result is:

result = [(a,c), (b)] 

how it?

i tried as:

results = [] p,c in zip(data,sub_lists):     x in data:         if p.intersects(x): ##.intersects return true if overlap else false             results.append(c) print results 

without downloading shapely, think want lists can replicated strings (or integers):

in [221]: data=['one','two','three']     in [222]: data1=['one','four','two']  in [223]: results=[[],[]] in [224]: in data1:     if in data:         results[0].append(i)     else:         results[1].append(i)    .....:           in [225]: results out[225]: [['one', 'two'], ['four']] 

replace i in data intersects tests. first sublist of results contains elements of data1 test true. second sublist contains elements false.

your question little confusing in data , sublists appear contain same elements. maybe aren't testing whether a in data (or intersect element of data), whether a intersects other element of [a,b,c], etc.

in case, key collecting results have 2 (or more) slots in results, can put i depending on test. results dictionary, or 2 different variables. e.g. results={'found':[],'lost':[]}.

do need work more on test?

a 'intersects with' of [b,c] b 'intersects with' of [a,c] c 'intersects with' of [a,b] 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -