好的,这是问题!
我创建了一个像这样的词典
a={'t1':[{seta1},{seta2},{seta3},{seta4}],
't2':[{setb1},{setb2},{setb3},{setb4}],
.
.
.
't100':[{setz1},{setz2},{setz3},{setz4}]}
其中't1','t2',....,'t100'是时间戳,{set1},{set2},{set3},{set4}是各个时间戳的不相交的集群集。
现在我想在时间戳中找到每个集合集与每个其他集合的交集。 即,假设
b={} # is my resulting dictionary
最初b为空,所以'b'包含整个a ['t1'],键't1'
b['t1']=a['t1'] #isn't this a deep copy? cos i replicating the values. Is there a way to achieve a shallow copy? thought of using .copy() and .update() method but couldn't figure out any possible way.
随着迭代的继续,我找到交叉点并更新结果字典如下。
k=[i&j for i in a[key1] for j in b[key2]]
#if intersections between a and b are empty sets, then i will create 'key1' in b and put the corresponding value of key1 in b
#if key1 is already present in b, then i will append the a[key1] value into b[key1] and remove the corresponding value from a[key1]
#if the intersections are found, and the length of each intersection is >2, i will do something like this
b[key2+','+key1] not in b.keys():
b[key2+','+key1]=[] #b[t1,t2]=non-empty intersections whose length is >2
b[key2+','+key1]=k #where k holds the intersection and the empty sets and intersections with length one are removed before this stage
假设我有seta1,seta2,seta3等。每个都有100个元素 然后找不到非常密集的交叉点? (100 * 100)有没有有效的方法来轻松找到十字路口?如何减少强度?我相信我读到的地方最糟糕的情况是交叉点
O(len(s)*len(t))
总结一下:
非常感谢任何帮助。 :) 谢谢你! :):)