Python 3 is the latest version of the Python programming language and was formally released on December 3rd, 2008.

learn more… | top users | synonyms (1)

2
votes
1answer
55 views

How could I shorten my code in this old graded homework?

I have this old graded homework, I am looking how to improve the or shorten the code, I have some lines with over 200 chars. ...
-3
votes
0answers
11 views

Need help understanding loop issue and building list, also receiving error message [on hold]

Goal of program is to establish grades for x # of students and to put studentid, name, totalscore, and lettergrade into a Tuple and then put the Tuples into a list to display all x # of students and ...
2
votes
2answers
64 views

Accurate sum of a range object in O(1)

I recently created a function calculating the sum of an arbitrary range object in \$O(1)\$: ...
3
votes
1answer
28 views
-4
votes
0answers
18 views
3
votes
2answers
39 views

Pairwise distance and residual calculation

I have a code for calculating the pairwise distances and the residuals of my data (X, Y, Z). Data is quite large (average of 7000 rows) and so my interest is code efficiency. My initial code is ...
6
votes
1answer
57 views

Representing integers as a sequence of bits

Here is a class Bits that I wrote in order to deal with sequences of bits that also need to be interpreted as non-negative integers (in case you are familiar with ...
-4
votes
0answers
27 views

Im learning python and i am trying to make a Rock, Paper, Scissors program [closed]

It should work according to basic logic so I think it is a syntax error or perhaps I am missing something. The last logic part is not working I think. It omits all when it is only suppose to omit any ...
3
votes
1answer
61 views

Python priority queue class wrapper

I'm trying to incorporate the advice found in https://docs.python.org/3.5/library/heapq.html in order to make a priority queue implementation (see corresponding section) in a class ...
4
votes
1answer
79 views
+50

Runge-Kutta 4th order using Python numexpr.evaluate()

I am implementing an ODE solver, where the user provides rates and coefficients as a string. ODE solver has to work with vectors. The best implementation I got so far is the following: ...
5
votes
0answers
56 views

Unfair die game

For this task, you're going to play a dice game, but first you must prepare for an overwhelming victory. The game itself is very simple. Both players roll a single die and whoever rolls highest ...
2
votes
2answers
47 views

Crank-Nicolson. Advection - Diffusion. Perfomance

I am writing an advection-diffusion solver in Python. I am quite experienced in MATLAB and, therefore, the code implementation looks very close to possible implementation in MATLAB. I implemented the ...
3
votes
2answers
74 views

Prime number generator in Python

I have made a Python program that can perform some prime number functions. For example, it can produce an endless output of sequential primes. I am looking for ways to make it faster and cleaner. When ...
4
votes
1answer
34 views

Noughts and crosses command line game in Python 3.5

Based on this Code Review answer, I have created a noughts and crosses game in Python, which asks for an index (1 to 9) and updates the grid, and displays it on the screen. I have done some very ...
5
votes
2answers
64 views

Parsing the lsblk output

I am a Python beginner learning Python 3. I have written two small functions that parse the lsblk output and return Linux physical and logical disks. Here is the first function: ...
4
votes
2answers
68 views

Password generator in Django

I am a system admin, not a developer, so this might be pretty horrible code. This is a password generator. The point of the attempt was to become more familiar with Django at a lower level. I current ...
0
votes
1answer
68 views

Phone troubleshooting questionnaire with Tk GUI [closed]

I have been tasked to create a GUI that asks the user questions about a mobile device.the GUI I have created asks the user a sequence of questions to try and come to a solution.However, I feel that my ...
3
votes
2answers
83 views

Python Day Finder

I have made a Python program to find the day of the week of an inputted date. I did not want to use the time or datetime module, ...
3
votes
1answer
43 views

Python configuration module for a web framework

I'm currently writing a web framework and I wanted to add a configuration module for reading environment variables and a configuration toml file. Here is the code. The comment in the ...
5
votes
5answers
477 views

Circular Array Rotation

My code works fine, but it's takes too much time, say around 65 seconds, for large input data. If there are 50,000 numbers in the list \$a\$ and we have to rotate the numbers 45,000 times then it ...
3
votes
1answer
52 views

Multivariable Gradient Descent in Numpy

Just recently started learning ML, first I've gone through the notes of Ng's Coursera stuff. While I have nothing against Octave, I'm trying to solve exercises in Python. It's my beginning with that ...
3
votes
1answer
73 views

Square free number

Square free no: It is an integer which is divisible by no other perfect square than 1. For example, 10 is square-free but 18 is not, as 18 is divisible by 9 = 3^2. The smallest positive ...
9
votes
2answers
111 views

TicTacToe in Python3 w/ Simple AI

Here is my version of TicTacToe on python 3.x I'm learning python for a several weeks and I will be very appretiated if you take a look on my script and review it! P.S. I've used NumPad to input ...
6
votes
2answers
82 views

Simple Hangman for Python

Assignment Criteria Create another version of the Hangman game, this time using Lists. The program should ask for the word to guess and the number of chances to be given. It should then ...
2
votes
0answers
60 views
+50

JVM wrapper for a Python function

Context: The following function is used a JVM wrapper for a Python function, which is executed in a SQL-like environment. If you're interested in example usage you can check Cumulate arrays from ...
4
votes
2answers
150 views

Find good numbers in a given range

This is the Good Numbers problem at Code Chef: A number is called a square-free number if there does not exist a number greater than 1, whose square divides the number. For example, 8 is not a ...
2
votes
1answer
51 views

Taking in data from several large files

I am working on a script in Python 3.5 that will take in data from several large files. The script takes a while to run, so I am trying to optimize the functions that take the longest. In particular, ...
2
votes
1answer
35 views

TeamCity TestComplete runner in Python

I am new to using Python and the following is the first script that I have written. I will execute a test complete project and will be started via team city. Once test execute has been called - the ...
4
votes
4answers
122 views

Taking a list of numbers and finding the two largest

The code ive written takes the user entered numbers and sorts them into a list and finds the two biggest numbers, im looking to make the code less verbose. any help/advice is greatly appreciated. <...
4
votes
1answer
40 views

Parts Inventory System

I have been working on some code for a basic inventory management system and I have all the features that I believe are need like adding parts displaying parts list and the such as you can see. I ...
-1
votes
0answers
31 views

References to constants values within a Python app — budtrack

I have written a Python application called budtrack, which has a purpose of monitoring a budget. I know I kinda reinvented 'the wheel', but the purpose of the project was to practice user requirements ...
4
votes
1answer
88 views

Decimal to Binary Conversion and vice-versa in Python

Given a decimal number I need to convert it into binary Given a binary number I need to convert it into decimal After the conversion I need to perform some operation on it (for example, addition). I ...
4
votes
2answers
98 views

Get nth prime number using sieve of Eratosthenes

I am tasked with being able to find the \$n\$th prime number. I've tried to implement something like the sieve of Eratosthenes in increments of 200. The code works and returns the \$n\$th prime number....
4
votes
3answers
173 views

Convert a numeric string to number but without python's built in function

I'd like to get a code review and some insights of whether I chose a good way to do this. What would other, clever ways look like. ...
2
votes
3answers
127 views
-3
votes
0answers
28 views
0
votes
0answers
13 views

Transforming text after preprocessing to tfidf vector and reducing the dimension using pca

I am not getting any error with this code. Please review it for writing it in a more optimized way so that it will take less memory space and run time. ...
4
votes
1answer
78 views

Knapsack greedy algorithm in Python

I implemented the well-known knapsack problem and now I would like to improve it using list comprehension or lambda. I don't want to use NumPy. Could you help me? ...
6
votes
2answers
84 views

Vanilla Markov chain in 18 lines

I am looking for advice on how I can improve this code. The objective is to make a vanilla Markov Chain text generator in the most concise way. I'm looking for advice on style, naming, 'elegance', and ...
11
votes
2answers
749 views

Let's speed that file sentence searching program

Intro: I've written a small piece of Python program which is looking for a given sentence in multiple sub directories of a given path. I'm looking for improvements regarding the speed of my script. ...
2
votes
0answers
45 views

Traning and testing of sentiment analysis

Here is my code which takes two files of positive and negative comments and creates a training and testing set for sentiment analysis using nltk, sklearn, Python and statistical algorithms. The ...
3
votes
2answers
76 views

Returning largest product of longest subsequence between min and max

This function returns the largest product of all elements of a list between the leftmost and rightmost min and max elements. Is there more readable and maybe compact way to rewrite the ...
1
vote
1answer
25 views

Displaying an arbitrary number of buttons and automatically arranging the buttons

It is supposed to take an arbitrary number of arguments, turn those arguments into buttons, and arrange those buttons in a way to give each individual button the largest area possible. Is there a ...
3
votes
1answer
29 views

Computing a list of divisors of a number

I developed the following Python functions when solving a few Project Euler problems, and since I'm not that familiar with Python, I'm curious at how I could improve them. The code consists of a data ...
3
votes
1answer
68 views

Multiple numbers calculator

This is my first ever Python program so I would really like to know if it's any good (I mean if it is well writen), and if not then how to make it better. I would also like to know if there is a way ...
2
votes
1answer
65 views

Monty Hall simulator in Python 3.x

I've been working on Python for the past few weeks trying to get my head around it's syntax/naming conventions/style/etc. I decided to make a monty hall sim to see how it looks in python. For those ...
3
votes
0answers
54 views

Validating HMAC-SHA256 signature in Python

I am trying to implement HMAC-SHA256 authentication into my Python RESTful API project. I am using Python Eve (built on top of Flask), started with an simplified HMAC-SHA1 example. My application is ...
4
votes
1answer
45 views

First touch with python decorator

I am getting familiar with decorators, and after a couple of tutorials i came up with a decorator that might is useful for me. Is this the proper way to use decorators? Any suggestion about the code? ...
3
votes
1answer
79 views

Simple Blackjack game in Python

I am trying to create a simple Blackjack game. I am using GIST because the code sample takes forever to use. Current code: ...