All Questions
245 questions
6
votes
1
answer
870
views
Python function that deeply "freezes" an object
I implemented a function that gets an object and returns its immutable counterpart. If the object contains another mutable object at any level, it freezes it too.
Is my code is good and/or can it be ...
6
votes
2
answers
188
views
Is this Python decorator a good idea to solve circular recursion?
I have several model classes, let's say A_0, A_1, ..., A_N
I have a method A_0.to_A_1() that calls A_1.to_A_2(), ... that calls ..., that calls A_(N-1).to_A_N()
So far so good, but A_N may then call ...
3
votes
1
answer
168
views
Pentomino solver in Python
When I was a child, I used to play Ubongo board game, recently I discovered Pentomino puzzle and I wanted to create a custom solver in python for it. Here is what I got:
...
2
votes
1
answer
145
views
Test whether every element in an array is equal to sum of subsequent elements
I want to ask how to improve this code. Is it well-written or should anything be changed? Please let me know. And is it a bad thing to use arguments to store some info, such as the argument value here?...
2
votes
1
answer
662
views
Find all permutations of string using recursion
Background: I am somewhat new to programming and only two weeks into learning Python. Currently trying to improve my understanding of recursion, which has been a tough concept for me to implement.
...
1
vote
1
answer
77
views
Checking several strings against a n-depth list of lists and returning one if its values
The data structure I am working with is a list of lists that is created by parsing a file.
The depth of the list can vary. The list can have n Strings before its child-value begins.
My current example ...
4
votes
0
answers
165
views
Finding the number of possible paths in a cave system (Python)
I've finally come up with working solution for day 12 of AdventOfCode, where you have to find the number of possible paths in a cave system following a given set of rules (described below). My ...
1
vote
1
answer
84
views
Parsing an XML tree of categories
I have parse function which is parsing tree of categories. I've written it in simplest way possible and now struggling with refactoring it.
Every nested loop is doing the same stuff but appending ...
2
votes
1
answer
96
views
Find all non-crossing tuples which has the same content with a given tableau
Let T be a semistandard Young tableau of rectangular shape. For example,
[[1,2,4],[3,5,6]]
is such a tableau, where [1,2,4] and [3,5,6] are columns. All non-...
3
votes
1
answer
216
views
generate combinations from list of numbers
generate all combinations from list of numbers,the combinations can be pair of two numbers
example 1 : list of 2 numbers [1,2]
[
[[1],[2]],
[[1,2]]
]
example 2 : ...
4
votes
1
answer
80
views
Optimising compatibility-conflict graph solution - python recursive routine
Background
I'm implementing an algorithm which localises overlapping sound sources using the time-difference-of-arrivals across 3 sensors [1]. Compatible 'triples' (e.g. with only 2 common sensors) ...
5
votes
2
answers
2k
views
Get two closest numbers in a list using recursion in python
I'm trying to use recursion to find the closest numbers in a list. I made a program that runs correctly without any errors but I want to know if there's a better way to write my program while still ...
1
vote
0
answers
52
views
Iterate tables from table id from href links until no table with specific table id is found
I am doing web scraping to the next web page (which is my root URL to start scraping tables): https://www.iso.org/standards-catalogue/browse-by-ics.html
What I am trying to achieve is to parse the ...
2
votes
1
answer
89
views
Locate Primitive Value in Nested Sequence Type - Iterative version is slower than equivalent recursive function
I'm looking for advice on how to improve the performance and/or style of these two search functions. This is just for fun and for practice: they are already fast enough for any application I would ...
2
votes
1
answer
127
views
Coin partitions
I am looking to obtain the partitions of coins that sum to a target amount
So I tried search online, but every single website loves to use this problem to show the benefits of dynamic programming. ...