set

Disjoint-Set forests in Python alternate implementation

被刻印的时光 ゝ 提交于 2019-12-11 23:27:41
问题 I'm implementing a disjoint set system in Python, but I've hit a wall. I'm using a tree implementation for the system and am implementing Find(), Merge() and Create() functions for the system. I am implementing a rank system and path compression for efficiency. The catch is that these functions must take the set of disjoint sets as a parameter, making traversing hard. class Node(object): def __init__(self, value): self.parent = self self.value = value self.rank = 0 def Create(values): l =

AttributeError: 'NoneType' object has no attribute 'add'

孤街醉人 提交于 2019-12-11 21:59:44
问题 I got the following error AttributeError: 'NoneType' object has no attribute 'add' while I tried this. not_yet_bought_set = set() . . . for value in set_dict.itervalues(): for item in value: not_yet_bought_set = not_yet_bought_set.add(item) I dont't get why I got this error, is it because I always make not_yet_bought_set new? I make this, because when I only do not_yet_bought_set.add(item) there wont be all the items from all values. I do not know why. value are sets and not_yet_bought_set

“Multiplication of Arbitrary Precision Numbers” in Scheme

走远了吗. 提交于 2019-12-11 20:28:34
问题 The following is code to a problem that I have been working on for a few days. The problem I encountered is that for some reason when I call: (apa-multi '(7 3 1 2) '(6 1 4)) the return is: '(4 8 9 5 6 8) The answer that it should output is '(4 4 8 9 5 6 8) When I call: (apa-multi '(3 1 2) '(6 1 4)) The output is: '(1 9 1 5 6 8) which is correct. I have debugged my code multiple times, and I can't seem to find out what the problem is (by the way, I know that the "remove-empty" function that I

Cartesian Products with sets in java

走远了吗. 提交于 2019-12-11 18:55:03
问题 I am trying to create a cartesian product method in java that accepts sets as arguments and returns a set pair. The code I have coverts the argumented sets to arrays and then does the cartesian product but i can't add it back to the set pair that i want to return. Is there an easier way to do this? Thanks in advance. public static <S, T> Set<Pair<S, T>> cartesianProduct(Set<S> a, Set<T> b) { Set<Pair<S, T>> product = new HashSet<Pair<S, T>>(); String[] arrayA = new String[100]; String[]

mySQLi prepared UPDATE statement

梦想的初衷 提交于 2019-12-11 18:37:51
问题 I seem to have an odd issue with my prepared update statement. I am performing an update operation as follows: $stmt = $db->prepare("UPDATE table SET id = ? WHERE email = ?"); $id = "test"; $email = "m@m.com"; $stmt->bind_param('ss', $id, $email); $stmt->execute(); The update works, in terms of adding "test" as the id in the database. However, it adds test to EVERY row that has an email value, not just the row that has the value of "m@m.com" as I intended. Am I doing something blatantly wrong

How to get Variable in Variable (%var1%var2%%)

人盡茶涼 提交于 2019-12-11 18:11:32
问题 I'm trying to get a String of an users input and then let the Text scroll. What I have so far: @echo off setlocal set /p myString=String: cls call :StringLenght result myString :ECHO set /a result=%result%-1 set myString=%mystring:~%result%% echo %myString% ping -n 2 localhost>nul cls :StringLenght <resultVar> <stringVar> ( setlocal EnableDelayedExpansion set "s=!%~2!#" set "len=0" for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do ( if "!s:~%%P,1!" NEQ "" ( set /a "len+=%%P" set "s=

Large anagram search not reading to end of set Python

让人想犯罪 __ 提交于 2019-12-11 18:04:24
问题 I've got a piece of code here that checks anagrams of a long list of words. I'm trying to find out how to search through every word in my long word list to find other anagrams that can match this word. Some words should have more than one anagram in my word list, yet I'm unable to find a solution to join the anagrams found in my list. set(['biennials', 'fawn', 'unsupportable', 'jinrikishas', 'nunnery', 'deferment', 'surlinesss', 'sonja', 'bioko', 'devon'] ect... Since I've been using sets,

How can I run a set method over lists in terms of dictionary keys / values to find unique items and list the comparison results?

空扰寡人 提交于 2019-12-11 17:41:45
问题 I have a dictionary with values as lists of text values. (ID : [text values]) Below is an excerpt. data_dictionary = { 52384: ['text2015', 'webnet'], 18720: ['datascience', 'bigdata', 'links'], 82465: ['biological', 'biomedics', 'datamining', 'datamodel', 'semantics'], 73120: ['links', 'scientometrics'], 22276: ['text2015', 'webnet'], 97376: ['text2015', 'webnet'], 43424: ['biological', 'biomedics', 'datamining', 'datamodel', 'semantics'], 23297: ['links', 'scientometrics'], 45233: ['webnet',

TypeError: 'int' object is not iterable while no iteration exists?

◇◆丶佛笑我妖孽 提交于 2019-12-11 17:24:11
问题 I am trying to do a BFS while Python gives me an int object not iterable error. Part of the code is visited, queue = set(), collections.deque( ((0, 0), [ (0, 0) ] ) ) # tuple: current location, path while queue: vertex = queue.popleft() i,j=vertex[0] if i+1<=dim-1 and (i+1, j) not in visited and X[i+1, j]==0: visited.add(( i+1, j) ) temp=( (i+1, j), vertex[1]+[(i+1, j)]) if temp[0]==(dim-1, dim-1): return True, temp[1] queue.append(temp) Under the while loop, I am doing any other iteration at

sorting data in specific order

↘锁芯ラ 提交于 2019-12-11 17:08:25
问题 Here my rowId's are like the below 1 1.1 1.2 . 1.9 2 2.1 . . 3 . . 9 . 9.9 10 10.1 List<MyBean> sortedList = rootItems.stream().sorted(Comparator.comparing(MyBean::getRowId)) .collect(Collectors.toList()); By using the above code I am getting the output like below. 1 10 11 12 2 2.1 2.2 . . but I want output like the below 1 1.1 1.1.1 1.1.1.1 1.2 1.3 . . . 1.9 10 11 . 2 2.1 2.2 2.3 . . 3 3.1 3.2 . . 4 . . . 9 9.1 9.2 . . 9.9 10 10.1 . . like this it need to proceed If I want like this which