equivalence-classes

Combine tuples in a list which have the same value [duplicate]

被刻印的时光 ゝ 提交于 2019-12-24 04:51:42
问题 This question already has answers here : Union find implementation using Python (4 answers) Find the intersection between sublists (2 answers) Finding common elements in list in python (4 answers) Closed 4 years ago . I have a list with tuples like this: L ={(1,2), (1,4), (1,3), (2,3), (3,4), (3,5), (4,5), (6,7)} I try to combine these to get equivalence classes (tuples of the same value are merged, like (1,2) and (2,3) becomes (1,2,3)). So you get: EQ = {(1,2,3,4,5), (6,7)} What's the

Microsoft.VisualBasic.FileIO.FileSystem equivalence in C#

僤鯓⒐⒋嵵緔 提交于 2019-12-23 10:03:12
问题 I use VS 2008, .net 3.5, C# projects. I need do the same functionally like Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory. Anyone says referencing the Microsoft.VisualBasic is often undesirable from within C#. Any association with VB from within C# code strikes me as undesirable. Using FileSystem class, this is a perfectly fine solution, but I prefer not references Microsoft.VisualBasic library. That one I would avoid. private static void DeleteDirectory(string destino) { //UIOption

Java: external class for determining equivalence?

假如想象 提交于 2019-12-22 04:38:21
问题 Java has a Comparator<T> for providing comparison of objects external to the class itself, to allow for multiple/alternate methods of doing ordered comparisons. But the only standard way of doing unordered comparisons is to override equals() within a class. What should I do when I want to provide multiple/alternate unordered comparisons external to a class? (Obvious use case is partitioning a collection into equivalence classes based on particular properties.) Assuming the end use is for

Python many-to-one mapping (creating equivalence classes)

 ̄綄美尐妖づ 提交于 2019-12-18 13:04:39
问题 I have a project of converting one database to another. One of the original database columns defines the row's category. This column should be mapped to a new category in the new database. For example, let's assume the original categories are: parrot, spam, cheese_shop, Cleese, Gilliam, Palin Now that's a little verbose for me, And I want to have these rows categorized as sketch, actor - That is, define all the sketches and all the actors as two equivalence classes. >>> monty={'parrot':

Is there a standard way to partition an interable into equivalence classes given a relation in python?

懵懂的女人 提交于 2019-12-10 03:54:27
问题 Say I have a finite iterable X and an equivalence relation ~ on X . We can define a function my_relation(x1, x2) that returns True if x1~x2 and returns False otherwise. I want to write a function that partitions X into equivalence classes. That is, my_function(X, my_relation) should return a list of the equivalence classes of ~ . Is there a standard way to do this in python? Better yet, is there a module designed to deal with equivalence relations? 回答1: I found this Python recipe by John Reid

Implementing equivalence relations in C++ (using boost::disjoint_sets)

Deadly 提交于 2019-12-07 05:36:09
问题 Assume you have many elements, and you need to keep track of the equivalence relations between them. If element A is equivalent to element B, it is equivalent to all the other elements B is equivalent to. I am looking for an efficient data structure to encode this information. It should be possible to dynamically add new elements through an equivalence with an existing element, and from that information it should be possible to efficiently compute all the elements the new element is

Implementing equivalence relations in C++ (using boost::disjoint_sets)

为君一笑 提交于 2019-12-05 11:13:28
Assume you have many elements, and you need to keep track of the equivalence relations between them. If element A is equivalent to element B, it is equivalent to all the other elements B is equivalent to. I am looking for an efficient data structure to encode this information. It should be possible to dynamically add new elements through an equivalence with an existing element, and from that information it should be possible to efficiently compute all the elements the new element is equivalent to. For example, consider the following equivalence sets of the elements [0,1,2,3,4]: 0 = 1 = 2 3 = 4

Is there a standard way to partition an interable into equivalence classes given a relation in python?

时光总嘲笑我的痴心妄想 提交于 2019-12-05 05:00:47
Say I have a finite iterable X and an equivalence relation ~ on X . We can define a function my_relation(x1, x2) that returns True if x1~x2 and returns False otherwise. I want to write a function that partitions X into equivalence classes. That is, my_function(X, my_relation) should return a list of the equivalence classes of ~ . Is there a standard way to do this in python? Better yet, is there a module designed to deal with equivalence relations? I found this Python recipe by John Reid. It was written in Python 2 and I adapted it to Python 3 to test it. The recipe includes a test to

Python: simple list merging based on intersections

雨燕双飞 提交于 2019-11-26 08:02:47
Consider there are some lists of integers as: #-------------------------------------- 0 [0,1,3] 1 [1,0,3,4,5,10,...] 2 [2,8] 3 [3,1,0,...] ... n [] #-------------------------------------- The question is to merge lists having at least one common element. So the results only for the given part will be as follows: #-------------------------------------- 0 [0,1,3,4,5,10,...] 2 [2,8] #-------------------------------------- What is the most efficient way to do this on large data (elements are just numbers)? Is tree structure something to think about? I do the job now by converting lists to sets and

Python: simple list merging based on intersections

一个人想着一个人 提交于 2019-11-26 03:29:59
问题 Consider there are some lists of integers as: #-------------------------------------- 0 [0,1,3] 1 [1,0,3,4,5,10,...] 2 [2,8] 3 [3,1,0,...] ... n [] #-------------------------------------- The question is to merge lists having at least one common element. So the results only for the given part will be as follows: #-------------------------------------- 0 [0,1,3,4,5,10,...] 2 [2,8] #-------------------------------------- What is the most efficient way to do this on large data (elements are just