【问题标题】:how find a maximal set or a superset from a list of sets (Maximal set is the set which is not subset of another set in the list) [duplicate]如何从集合列表中找到最大集合或超集(最大集合是不是列表中另一个集合的子集的集合)[重复]
【发布时间】:2014-06-06 06:11:53
【问题描述】:

这是关于根据密度标准在图中找到密集社区,下面的所有集合都是图的密集社区

list L=[set([1]), set([2]), set([3]), set([4]), set([5]), set([6]), set([7]), set([8]), set([1, 2]), set([1, 3]), set([1, 4]), set([3, 4]), set([1, 3, 4]), set([1, 5]), set([2, 5]), set([4, 5]), set([1, 2, 5]), set([1, 4, 5]), set([2, 6]), set([4, 7]), set([8, 5]), set([8, 7])]

我需要得到这个列表的最大集合,即列表中的 set([1,4,5]) 是最大的集合集合([1]),set([4]),set([5]),set([1,5]),set( [1,4]) 和 set([4,5]) 所以我只需要打印出 set([1,4,5]) 同样 set([1]),set([3]).set([ 4]),set([1,3]),set([1,4]),set([3,4]) 有一个最大集合 set([1,3,4]) 所以我需要打印出来只有 set([1,3,4]) 如您所见 set([1,2,5]) 是最大集,所有不是较大集子集的集都被视为最大集,所以我需要只获取不是更大集合的子集的最大集合

【问题讨论】:

  • 你之前不是问过这个问题吗?
  • 请不要转发同样的问题。

标签: python python-2.7 python-3.x numpy set


【解决方案1】:
L=[set([1]), set([2]), set([3]), set([4]), set([5]), set([6]), set([7]), set([8]), set([1, 2]), set([1, 3]), set([1, 4]), set([3, 4]), set([1, 3, 4]), set([1, 5]), set([2, 5]), set([4, 5]), set([1, 2, 5]), set([1, 4, 5]), set([2, 6]), set([4, 7]), set([8, 5]), set([8, 7])]


#this grouping the list by there length ...
values = set(map(lambda x:len(x), L))
newlist = {x:[y for y in L if len(y)==x] for x in values}
maxlen=max(values)

#checking for the subset.if no subset.it is returned

for i in values:
    print [ key for key in newlist[i] if not any([ val.intersection(key)==key for j in values if j !=i for val in newlist[j] ])]


#output =[set([2, 6]), set([4, 7]), set([8, 5]), set([8, 7])] [set([1, 3, 4]), set([1, 2, 5]), set([1, 4, 5])]

【讨论】:

  • 谢谢...你是男人..
  • @user2014111 快乐是我的
  • 我无法接受..
  • @user2014111 没问题。只是问
猜你喜欢
  • 2021-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-15
相关资源
最近更新 更多