12,133 questions
Advice
0
votes
4
replies
57
views
Finding substrings from the string using sets: algorithm's logic
I was solving the algorithm problem: find all unique substrings from the string, using sets.
Here is the model solution, but I can't understand what line 6 means. Why does the end go up to length + 1? ...
1
vote
0
answers
34
views
Extracting unique values from multiple sets [duplicate]
I have 3 sets:
alice = {'first_kill', 'level_10', 'treasure_hunter', 'speed_demon'}
bob = {'first_kill', 'level_10', 'boss_slayer', 'collector'}
charlie = {'level_10', 'treasure_hunter', 'boss_slayer',...
Best practices
0
votes
6
replies
29
views
Nested Sets: which languages support this?
What functional or mixed functional programming languages support nested sets, akin to the usage in mathematics and set theory? Specifically those with a REPL?
I tried Python and couldn't get nested ...
Advice
0
votes
5
replies
92
views
How to separate variables on each line in a batch SET statement?
I have some data fields gathered in a SET statement like this:
set "datastr=%num_cde%, %id_achat%, %modele%, %sysfam%, %serial%, %ldt%"
later assigned to an email body as:
SET "...
1
vote
1
answer
113
views
What is the difference between session_authorization and set role
In Postgres, you can set current_user by:
set session_authorization = 'new_user';
and
set role 'new_user';
While I like the shorter syntax, I'm asking if there is a difference in functionality ...
0
votes
4
answers
183
views
How to create objects from sets?
How can I create objects from a Set?
const dupObj = [{ id: 1, value: 'a' }, { id: 2, value: 'b' }, { id: 1, value: 'c' }];
const uniKeys = [...(new Set(dupObj.map(({ id }) => id)))];
// [ '1', '2' ]...
3
votes
2
answers
286
views
Is iteration order of a set in Python preserved until that set is modified?
According to the Python documentation, set is a mutable unordered collection.
Usually, it's implemented as a hash table that stores references to objects as its keys. Comparing to dict (which is also ...
8
votes
3
answers
1k
views
How can I create an array of arrays of strings of varying lengths in C?
I am trying to solve the problem posed in this question. Here the OP asks that given a 15 element set, its 2^15 element power set be generated in a manner such that the elements of the power set are ...
4
votes
2
answers
185
views
Combination generator written in C : works for big n but for small n when n=0 or n=k crashes saying "segmentation fault"
Let's say I have a box and there is a bunch of balls in that box. I can label each ball with a character while making sure no two balls get the same character as labels. I get a string this way. Let's ...
0
votes
3
answers
103
views
How Do Sets and Set Comparisons Work in Python? [duplicate]
I'm learning Python coming from some beginner-level experience with Java. It all makes sense for the most part, but one of the exercises kind of made me wonder what actually happens within Python.
...
0
votes
2
answers
67
views
How can I add elements to an existing Set in GAMSPy?
I'm working with the GAMSPy Python API and using Set objects to define sets in a GAMS model. I can define a set like this:
from gamspy import Container, Set
m = Container()
regions = Set(m, name=&...
2
votes
3
answers
211
views
Writing a Von Neumann Ordinal generator in C : Problem with malloc
I want to write a computer programme that will do the following things :
1a. It will make an array 3 characters long.
£££
2a. It will then initialize the array with the string "{_}" and ...
1
vote
2
answers
76
views
A dead loop problem in JavaScript about Set
Why the following code caused dead loop?
const s = new Set([1]);
s.forEach(e => {
s.delete(e)
s.add(e)
})
I tried to change the order about delete and add operation,the dead loop ...
0
votes
2
answers
111
views
Would python function any() iterate or just locate the item if used with a hashset
to clarify, it would be used like any(set()). I am asking for efficiency sake.
Example: if any(fnmatch(a,b) for a in set)
where a would be an item in a set and b would be a string.
5
votes
3
answers
293
views
Fastest way to find the least amount of subsets that sum up to the total set in Python
Say I have a dictionary of sets like this:
d = {'a': {1,2,8}, 'b': {3,1,2,6}, 'c': {0,4,1,2}, 'd': {9}, 'e': {2,5},
'f': {4,8}, 'g': {0,9}, 'h': {7,2,3}, 'i': {5,6,3}, 'j': {4,6,8}}
Each set ...