Tagged Questions
Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.
3
votes
1answer
32 views
Script to generate documents based on conditionals and CSV data
I wrote this script a while back to generate press releases. It consumes a csv of data where each row contains the data for a country and fills in values in pre-written text based on the data. In its ...
5
votes
2answers
32 views
Validating config files and separating back-end from front-end
I'm writing a simple script which will search a source directory for certain types of files and move them to a destination directory. I'm using it as an opportunity to practice writing some ...
6
votes
1answer
42 views
Python script audibly represents itself
I was just messing around with python making wav files; when I came up with this (what I think is) pretty neat script. It takes each character and represents it ...
8
votes
2answers
142 views
Symmetric Square
I was given an assignment to ensure that a list was symmetric.
I built it in a way that worked and it passed the tests. But I wanted to see if it could've been written more efficiently and still ...
5
votes
4answers
554 views
Simple Rock, Paper, Scissors in Python
I have looked at many different approaches to this game online, but as someone who isn't very experienced with Python, I may not be aware of what others are doing right.
Here is my code:
...
-4
votes
0answers
37 views
Pokemon type game in python 3 [on hold]
Im trying to make a simple pokemon style game in python 3. I sucsessfully made the game with 3 moves that the player could use: punch kick or heal. I then wanted to expand the game and add other ...
2
votes
1answer
30 views
K-means clustering algorithm in python
Here is my implementation of the k-means algorithm in python. I would love to get any feedback on how it could be improved or any logical errors that you may see. I've left off a lot of the ...
0
votes
0answers
7 views
Asserting Point in Plane (3D) [on hold]
So I am trying to determine if a series of points in three-space are on a known plane. A way to determine this I found here: http://stackoverflow.com/a/17227310/1695680
So I have the following ...
3
votes
1answer
35 views
N-puzzle program solved using A* search
I coded the following program to solve the n-puzzle problem with n = 3. Are there any suggestions regarding readability and variable names?
...
5
votes
4answers
88 views
Pi-calculating program
I saw this question and answer about calculating pi on Stack Overflow, and I decided to write my own program for calculating pi. I used Python and only integers (I didn't want to use floating point ...
3
votes
1answer
64 views
Counting Lines and Sum of Lines
I have a small function that when passed a str that names a file that contains a program; it returns a 2-tuple with the number of the non-empty lines in that program, and the sum of the lengths of all ...
3
votes
4answers
143 views
Count the ways to partition an array into two equal sets
I need to count the number of ways to partition an array into two contiguous arrays such that those arrays contain exactly same set of items.
Suppose ...
2
votes
1answer
35 views
Efficiency and correctness of my randomized selection algorithm
Instead of picking a random pivot I'm shuffling the array beforehand. Does it count as randomization and is it efficient to shuffle or pick a random pivot and is my implementation pythonic?
Problem
...
1
vote
3answers
19 views
Word/expression list frequency distribution
I have another Python issue, creating a frequency distribution out of a text matching a predefined wordlist. In fact, I work with more than 100,000 text files (each consisting of about 15,000 words), ...
3
votes
2answers
65 views
Recursive functions for sorting
I made a few recursive functions for learning purposes which do a variety of tasks. Here is my current and functioning code:
...
1
vote
1answer
32 views
Find the peak element using BS
A peak element is an element that is greater than its neighbors.
Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.
The array may contain multiple peaks, in that ...
3
votes
1answer
28 views
Iterate over large list of lists and replace its elements
I have a large list of lists, where each list contains words/characters as elements, and each list is of different length and may contain same words/characters more than once, as for example:
...
-3
votes
2answers
33 views
Cleaning up code? [on hold]
This was my first attempt at a github pull request, and I was asked to cleanup my code before it will be merged. I am not familiar with cleaning up code, so I have no idea what could be cleaned.
...
5
votes
1answer
25 views
Fast Thread- and multiprocess-safe file operations in python under Linux
I'm trying to implement an alternative to python built-in open(), but safe for use in multi-threaded and multiprocessing environment. I'm using advisory locking, ...
3
votes
2answers
52 views
Reverse Polish Notation calculator in Python
After reading the definition, I made a simple Reverse Polish Notation (RPN) calculator in Python.
Originally it had just 4 operators (using import operator and a ...
4
votes
2answers
90 views
+50
Functions with mutable and non-mutable named tuples
I am making some functions within a function for learning which when passed information about a named tuple: it returns a reference to a class object from which we can construct instances of the ...
0
votes
0answers
13 views
Codingbat Python Array123 [on hold]
So I'm working on learning to program, using codingbat as practice, and ran into a problem and can't quite figure out why my code isn't working.
So the question is:
Given an array of ints, return ...
-1
votes
0answers
18 views
Find the triplet for a set in Python [closed]
This is my assignment, and this is what I've tried so far:
Alternative 1:
...
7
votes
2answers
51 views
Adapting a bilingual program to support users with learning disabilities
I have a very large class which serves as the BaseClass for many AdapterClasses. The base class consists of methods that can be ...
0
votes
0answers
10 views
3D plotting solutions to simultaneous differential equations [closed]
I am trying this for hours now I don't see any logical problem in my code.
I am plotting solutions to simultaneous differential equations using RK4 method with the initial conditions and equations ...
-1
votes
0answers
12 views
Pyside QGraphicsView, how to insert multiple objects and text in a horizontal line? [closed]
I am trying to arrange a series of rectangles in QGraphicsView with text above them. I can create the rectangles, but they stubbornly wont move from the middle of the window to the top left for ...
1
vote
1answer
21 views
5
votes
1answer
58 views
Flooring cost calculator
I've made a small program that calculates the cost of flooring for a given area based on the price per sqft and total sqft. I have only been programming for a few days now so I am sure that there are ...
2
votes
2answers
40 views
Image download handler app
I have a paid app on the app engine. At the moment, usually there is only one instance. The app has a download handler that sends an image after re-sizing it if it is too big. The problem is: if a web ...
2
votes
1answer
38 views
Python script that does a git diff
I have created a small script that aims on comparing two versions of a file by doing a git diff. Is there a better way to code it?
...
2
votes
0answers
24 views
Tested cartesian plane utility
I am starting to explore automated testing of code, so I decided to write some trivial code about the cartesian plane and test it. I am particularly interested in automated testing conventions and ...
0
votes
1answer
23 views
Temperature dependent 1-d conduction in Python? [closed]
I'm trying to write a Python code that is a numerical solver for 1-d heat conduction (using FVM) with a temperature dependent thermal conductivity. It looks like my main challenge now is getting rid ...
5
votes
2answers
106 views
Kolmogorov-Smirnov function
I'm trying to compare two lists of floating point data and see if they might have come from different underlying distributions. The two samples are a before and after, so by comparing the two I ...
4
votes
2answers
52 views
Opening and writing multiple files using minimum script
Can it possible to make this script short, so that multiple data and multiple output file can be managed efficiently?
...
3
votes
1answer
51 views
2 way communication Python socket
I'm trying to create a 2 way communication socket in python. The socket will listen for connections from the client until it gets the data formatted in string like this: 'PHONENUMBER|STATUS'. I will ...
0
votes
1answer
73 views
Need fast csv parser for Python to parse 80GB csv file [closed]
I am looking for the fastest way to parse an 80GB csv file with 300 columns in Python.
The csv file does not have backquote commas, e.g a,"blah,blah,blah",c
I ...
1
vote
1answer
38 views
Simplifying the code with same list comprehensions
I have such method where:
primary_images is dict,
additional is ...
0
votes
2answers
69 views
Two permutation iterators for classes in Python with and without a generator
I am just testing out a couple of small classes for learning purposes. Here is my current working code:
...
3
votes
3answers
70 views
Functions taking iterables: peaks, compress, and skipper
I am just testing out a few small functions for learning purposes:
...
14
votes
1answer
130 views
Remapping and interpolating 255x1024 array
I have a function that accepts a \$255\times1024\$ array and remaps it to another array in order to account for some hardware related distortion (lines that should be straight are curved by the lens). ...
0
votes
0answers
18 views
Reload pickled objects into dict - assigned to variable name from file name
I'm doing a bunch of work with echonest audio objects (as returned by the echonest API) in the Python CLI and rather than having to recreate them each time, they can be saved.
This bit of code ...
0
votes
0answers
23 views
python iterate 'over' a integer [closed]
The problem: I have a list with n items and I need a loop that loops n times.
Edit I do not use the list inside the loop. But ...
-2
votes
0answers
15 views
Sorting a text file via Numerical and Alphabetical form [closed]
So for a task at school I have to sort data entered in to a text file. So far I have set it up so that it is able to print data to the file, but after time trying I am still unable to make it so it ...
4
votes
2answers
102 views
Algorithm maths quiz + write to a text file
Are there any ways I can clean this code up to make it more user-friendly?
...
3
votes
2answers
632 views
Tic-Tac-Toe solver
As a programming exercise, I've attempted a Tic-Tac-Toe solver which takes a finished board and determines a winner.
On top of checks for malformed input/ambiguous games (e.g. both players with ...
6
votes
1answer
133 views
4
votes
2answers
48 views
Reading and Writing in same script
I just finished working through Exercise 16 of Learn Python The Hard Way.
To further study, I wanted to create a script that will read and display a file's contents on screen, and then have the user ...
-2
votes
0answers
15 views
4
votes
0answers
35 views
Extending Exceptions with module-specific prefix, intended for parsing error reporting
For one of my [WIP] project, I extended the dictionary class a lot with specific handlers, as such I determined that I wanted KeyError and ...
10
votes
2answers
127 views
Gimme some random passwords
pwgen is a nice password generator utility.
When you run it, it fills the terminal with a bunch of random passwords,
giving you many options to choose from and ...