All Questions
18 questions
3
votes
2
answers
4k
views
Capitalize a sequence of lines entered via console input and print/return
I'm running through the popular python practice exercises located at github:
https://github.com/zhiwehu/Python-programming-exercises/blob/master/100%2B%20Python%20challenging%20programming%20exercises....
2
votes
1
answer
102
views
Most efficient way to find spatial order from a list of tuples (Python)
I have a circle-growth algorithm (line-growth with closed links) where new points are added between existing points at each iteration.
The linkage information of each point is stored as a tuple in a ...
3
votes
1
answer
489
views
Filling values for nested dictionaries
I have a text file where any name followed with sequence word is considered a dictionary. The task is to go through the keys and values of a particular dictionary, which is already identified, and see ...
2
votes
1
answer
9k
views
Computing the powerset of a list
I've written the following code for computing the powerset of a list (we consider the list has all distinct elements, although it doesn't really matter).
Can this function be further optimized?
<...
7
votes
2
answers
716
views
Recursive function and memorization to find minimum operations to transform n to 1
I'm a new, self-taught programmer working on the Google FooBar challenge. I've submitted my answer (code at bottom) and it was accepted, but I'd like suggestions on how to improve my solution.
...
6
votes
1
answer
482
views
Ackermann function in Python 2.7
I'm relatively new to Python. I just want some constructive feedback on how to improve my code efficiency, style, error handling, etc.
In this case, I've programmed the Ackermann function, but it won'...
19
votes
5
answers
65k
views
Get value from dictionary given a list of nested keys
I would like to get a deeply-nested value, for example {"a":{"b":{"c":"myValue"}} by providing the keys to traverse. I tried chaining together .get() but that didn'...
8
votes
2
answers
2k
views
Python traverse a directory recursively and print contact numbers
I am writing a python code to recursively traverse a directory containing only text files and then print the 10 digit Indian phone number and all its variants. I am very new to python and I have ...
2
votes
2
answers
613
views
Decompress files files in a directory recursively
Currently I'm trying to redo this code to avoid the breaking line because of the 80 characters rule:
...
2
votes
1
answer
2k
views
Tower of Hanoi: graphical representation of optimal solution
I wrote a program to show graphically the solution of the problem of the Tower of Hanoi. Here is a video of an example run.
The logic of the solving is taken from StackOverflow (see links in ...
3
votes
1
answer
8k
views
Count digits in a given number using recursion
Here is my code that finds the number of digits in a given integer (either positive or negative). The code works and results in expected output.
...
5
votes
1
answer
4k
views
Calculate the arclength
I am trying to estimate a good approximation for the arclength of the curve \$ y = \sqrt{1-x^2}\$ for \$x \in [0, 1]\$. I did this using a Bezièr curve, and made it so that the area under the two ...
2
votes
1
answer
823
views
Find all distinct subsets that sum to a given number
The function wants to achieve to find all distinct subsets that sum up to an given number.
...
2
votes
2
answers
232
views
Computing the largest substring starting with a substring
Given a string and a non-empty substring sub, compute recursively the largest substring which starts and ends with sub and return its length.
...
5
votes
2
answers
2k
views
An implementation for the double factorial
I have written this piece of code that implements the double factorial in Python both iteratively and recursively; the code works without problems, but I'm interested in improving my overall ...