set

removing duplicates of a list of sets

断了今生、忘了曾经 提交于 2019-12-22 03:22:01
问题 I have a list of sets : L = [set([1, 4]), set([1, 4]), set([1, 2]), set([1, 2]), set([2, 4]), set([2, 4]), set([5, 6]), set([5, 6]), set([3, 6]), set([3, 6]), set([3, 5]), set([3, 5])] (actually in my case a conversion of a list of reciprocal tuples) and I want to remove duplicates to get : L = [set([1, 4]), set([1, 2]), set([2, 4]), set([5, 6]), set([3, 6]), set([3, 5])] But if I try : >>> list(set(L)) TypeError: unhashable type: 'set' Or >>> list(np.unique(L)) TypeError: cannot compare sets

Compare sets inside a set

我与影子孤独终老i 提交于 2019-12-22 01:32:52
问题 I have a set like this : Set<Set<Node>> NestedSet = new HashSet<Set<Node>>(); [[Node[0], Node[1], Node[2]], [Node[0], Node[2], Node[6]], [Node[3], Node[4], Node[5]]] I want to compare and merge sets that are inside the nested set. [0,1,2] and [0,2,6] has element in common. so should merge them to form 0,1,2,6. The output should be like this: [[Node[0], Node[1], Node[2], Node[6]], [Node[3], Node[4], Node[5]]] Is there any efficient way? 回答1: You can use Collections.disjoint(Collection c1,

Minimizing the number of boxes that cover a given set of intervals

大憨熊 提交于 2019-12-22 00:25:57
问题 this is a question for the algorithms gurus out there :-) Let S be a set of intervals of the natural numbers that might overlap and b a box size. Assume that for each interval, the range is strictly less than b . I want to find the minimum set of intervals of size b (let's call it M ) so all the intervals in S are contained in the intervals of M . Trivial example: S = {[1..4], [2..7], [3..5], [8..15], [9..13]} b = 10 M = {[1..10], [8..18]} // so ([1..4], [2..7], [3..5]) are inside [1..10] and

How to create separated XML nodes with “set” in Puppet using Augeas?

点点圈 提交于 2019-12-21 23:51:56
问题 I am using the Augeas tool for Puppet 3.2 and I am trying to create an XML file. I want to be able to add multiple fields with the same name into my XML doc. For instance, I want to separate node2/location2 from node1/location1 by placing it in its own "node" field. This is my code: augeas { "update template": lens => "Xml.lns", require => File["${buildpath}/tempfile.xml"], incl => "${buildpath}/tempfile.xml", changes => [ "set member/acceptors[#attribute]/node[#attribute]/nodeIdentity[

Merge sets when two elements in common

假装没事ソ 提交于 2019-12-21 23:07:31
问题 This is the follow up of compare sets I have Set<Set<Node>> NestedSet = new HashSet<Set<Node>>(); [[Node[0], Node[1], Node[2]], [Node[0], Node[2], Node[6]], [Node[3], Node[4], Node[5]] [Node[2], Node[6], Node[7]] ] I want to merge the sets when there are two elements in common. For example 0,1,2 and 0,2,6 has two elements in common so merging them to form [0,1,2,6]. Again [0,1,2,6] and [2,6,7] has 2 and 6 common. so merging them and getting [0,1,2,6,7]. The final output should be : [ [Node[0]

Set properties to jsf managed-bean

£可爱£侵袭症+ 提交于 2019-12-21 21:43:34
问题 Have following first .jsf: <ui:repeat var="prod" value="#{showProducts.decoys}"> <h:form> {prod.price} {prod.weight} {prod.size} > <h:commandButton value="Buy" action="shoppingCart"/> </h:form> </ui:repeat> Have following shoppingCart.jsf: <h:form> <h:dataTable value="#{prod}"> <h:column> #{prod.name}<br/> </h:column> <h:column> #{prod.price}<br/> </h:column> <h:column> <h:inputText value="#{prod.count}" size="3"/> </h:column> </h:dataTable> <h:inputText value="#{order.phone}"/><br/> <h

how to convert list of lists to a set in python so I can compare to other sets?

痴心易碎 提交于 2019-12-21 17:57:45
问题 I have a list users_with_invites_ids_list , formed by loop where I append values to the list, in python that looks like this: ...[ObjectId('55119e14bf2e4e010d8b48f2')], [ObjectId('54624128bf2e4e5e558b5a52')], [ObjectId('53a6e7bc763f4aa0308b4569')], [ObjectId('55241823bf2e4e59508b494c')]] when I try: users_with_invites_ids_set = set(users_with_invites_ids_list) I get: TypeError: unhashable type: 'list' How do I convert this list of lists to a set? EDIT based on answer I've done the following:

Difference between two ranges

给你一囗甜甜゛ 提交于 2019-12-21 12:33:06
问题 I can find plenty of questions and example regarding the 'Union' and 'Intersect' VBA methods but I can't find anything much regarding a 'Set Difference' method? Does this exist (other than by using combinations of union and intersect)?. I'm trying to find a simple way of getting all of range1 excluding any of range1 that overlaps range2 without knowing the size or shape of either range. Any help would be greatly appreciated. EDIT. Attempted solution where rng1 is the red section and rng2 is

Scala: Contains in mutable and immutable sets

倾然丶 夕夏残阳落幕 提交于 2019-12-21 09:19:18
问题 I've discovered a strange behavior for mutable sets which I cannot understand: I have a object which I want to add to a set. The equals method for the class is overridden. When I add two different objects to the set, which produces the same output for equals method, I get a different behavior between mutable and immutable sets for the contains method. Here is the code snippet: class Test(text:String){ override def equals(obj:Any) = obj match { case t: Test => if (t.text == this.text) true

Python dictionary that maps strings to a set of strings?

好久不见. 提交于 2019-12-21 07:05:11
问题 I would like to be able to make a Python dictionary with strings as keys and sets of strings as the values. E.g.: { "crackers" : ["crunchy", "salty"] } It must be a set, not a list. However, when I try the following: word_dict = dict() word_dict["foo"] = set() word_dict["foo"] = word_dict["foo"].add("baz") word_dict["foo"] = word_dict["foo"].add("bang") I get: Traceback (most recent call last): File "process_input.py", line 56, in <module> test() File "process_input.py", line 51, in test word