Tagged Questions

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.

learn more… | top users | synonyms

1
vote
0answers
29 views

Fastest way of calculating mean values for each indices

I have two 2d arrays of equal shapes: given_array and reference_array. I have to write a file for each unique value of the reference_array computing mean values where the unique value are in the given ...
-1
votes
0answers
14 views

Creating a fixed calculator in Python 3 [on hold]

I am new to Python and I am trying to create a calculator to do a complex calculation. I need it to take input from a user and do deductions and multiplication based on that input. The scenario ...
0
votes
0answers
14 views

Inheritance after instantiation? [on hold]

Problem When writing context-aware class wrappers, I found that regular inheritance wasn't usable. Leaving me with the task of writing very light wrappers over the "parent" class wrapper: ...
1
vote
2answers
34 views

Keeping attribute names simple when using getters and setters

Is the use of _pn in __init__ pythonic? It seems that most examples change the actual attribute to ...
0
votes
0answers
5 views

TextFile into a dictionary [on hold]

I need help with reading my TextFile into a dictionary. My textfile is the following: loan 2 debt 3 rate 2 help 1 cousin 1 lawyer 1 Now I need to convert this into a dictionary. I have experimented, ...
2
votes
0answers
9 views

Parsing URLs in Pandas DataFrame

I'm working on a project, and the client needs their Google AdWords destination URL query parsed, and the values spell checked to eliminate any typos (use instead of us, etc). So what I'm doing is ...
2
votes
1answer
33 views

Word Jumble in Python

This game that I semi coded is a little bulky and kind of boring. I want to know if there is anything simple I can do to shrink it and add a little spice to the code. ...
3
votes
3answers
24 views

Flask route to pull data from database for getJSON to process

I am developing a reporting application in Flask where I pull data in a route function from a postgresql database and jsonify the data. On the client side I have ...
1
vote
0answers
16 views

Calculating Exponential Moving Average in Python

I'm in the process of creating a forex trading algorithm and wanted to try my shot at calculating EMA (Exponential Moving Averages). My results appear to be correct (compared to the calculations I did ...
2
votes
1answer
29 views

Making Tic-Tac-Toe winning check more efficient

My code works perfectly fine and I would just like to clean it up a little. From the research I've done, I cannot find anyone that used a multidimensional list to a game of TTT. I'm just looking for a ...
-2
votes
0answers
12 views

Text-Based game isn't accepting user input to flow through the next options [on hold]

I'm doing a text based game for an assignment, and I can't seem to get this bit of code to work properly. For some reason when it gets to the if userInputList[0]=="yes": It's not going onto the next ...
-1
votes
0answers
20 views

Python: URL Web Crawler for wikipedia stuck in loop [on hold]

I'm currently coding a program that's supposed to create a list of all english wikipedia articles. It currently works fine for a few seconds but then it gets stuck in an infinite loop on one ...
9
votes
1answer
988 views

Amateur RPG Fun

I am looking for this code to look neater, and if possible, less bulky. I am new to def and to dictionaries, so I think throwing a few of those in here could ...
2
votes
1answer
33 views

Extracting a subgraph

Given a huge graph, I want to traverse it, in the fastest way possible, and extract a subgraph with the following properties: the starting node is specified the maximum number of elements and max ...
4
votes
1answer
34 views

Streaming hacker news posts

Hacker News recently released an official API. Unfortunately, it cannot be used to get the newest posts submitted. I wrote a script to provide a faux streaming-api like method (like praw reddit's ...
0
votes
1answer
23 views

Improving excution time for list and sampling in Python

Here is my code for generating edge list based on Price model algorithm. I think there have two points to reduce execution time: use proper data type use faster random sampling Originally, I used ...
7
votes
4answers
317 views

Kaprekar's constant

I'm new to Python and as a first exercise, I've written a function (module?) to calculate Kaprekar's constant using Python 3. I'd like some feedback on whether this is Pythonic enough, and if I can ...
1
vote
1answer
32 views

Random Distribution to fit an Average Python

This is from my own question on Stack Overflow. I want to get average numbers from a range such that they fit an intended average. I expect something bell-curve-like, but asymmetrical unless the ...
1
vote
2answers
69 views

Stop connecting to a server after n unsuccessful attempts

I am trying to connect to a server. If the connection goes through, then print an apt message. If the connection does not go through, try for a total of n times. And quit after the nth attempt ...
-3
votes
0answers
32 views

adding elements to list in python [on hold]

Sorry if this is a silly question.In python result = [] if i.isalpha(): result += [i] or ...
1
vote
1answer
34 views

Motor degree movement function

I want to control a motor which rotates a device over a gear. Input values for the device are from 0 to 360 degrees. The motor should always rotate the device the shorter way around. For example, if ...
3
votes
2answers
57 views

List all classes in a package directory

I have a package directory pkg with several classes that I would like to build into a convenient dict property. The structure ...
1
vote
3answers
67 views

Basic text editor in Python with Tkinter

I have finished writing my nice and little text editor in Python with Tkinter. I tried to achieve the best user experience that I could. I want this code to be 2/3 compatible, I tested it in both ...
3
votes
3answers
749 views

Calculate highest prime factor very slow

Sometimes when I write a Python 3.x script with too many nested loops and some big values it just takes too long to give the answer. How can I optimize my code so that it runs faster, or where should ...
5
votes
0answers
50 views

Virtual machine management with decorated selfies

I have a class which provides various methods for retrieving information from a VMware vSphere environment. Over the time my class got extended and became large, so I thought I should spend some ...
4
votes
2answers
102 views

Testing whether a given string has unique characters

Here is my code which tests whether a given string has unique characters. The function is_unique which does a linear search for each character in the string is ...
1
vote
1answer
40 views

Drawing a dashed line with pygame

...
5
votes
1answer
97 views

Codility MaxCounters Peformance in Python capping out at 77% performance

My problem is quite similar to the question found here, except I am attempting to answer the question in Python. Given an array of N counters, all initialized to 0, and an array ...
2
votes
0answers
46 views

Binary Index tree optimization

I have written code for binary index tree. My problem is there are many functions based on the binary index tree the function stores the sum of element within a given range of binary index tree and my ...
2
votes
1answer
64 views

Conway's Game of Life without objects

I was wondering if anyone could provide some feedback on my solution to Conway's game of life. I tried to solve it without using objects. It returns a dictionary of living points on a grid and points ...
1
vote
0answers
20 views

Is monkeypatching __builtin__ in tests like this an absurdly complicated practice?

My hunch: Probably. I'm testing a little magic behaviour of my script that automatically reads from ~/.ghtoken to do automagic authentication on GitHub API ...
3
votes
1answer
30 views

Rename files to titlecased

I wrote this Python script to rename specified files to "titlecase", for example: hello.txt to Hello.txt ...
2
votes
2answers
73 views

Extended Euclidean algorithm and modular multiplicative inverse element

After my first exercise here is another. Again, this is exactly that: Exercise, which means that the output doesn't necessarily need to be beautifully formatted, etc. I probably have some variable ...
3
votes
2answers
110 views

Evaluating f(N,R) mod(m)

The goal is to find \$f(n,r)\mod(m)\$ for the given values of \$n\$, \$r\$, \$m\$, where \$m\$ is a prime number. $$f(n,r) = \dfrac{F(n)}{F(n-r) \cdot F(r)}$$ where $$F(n) = 1^1 \cdot 2^2 \cdot ...
4
votes
3answers
99 views

Prime less than N that is a sum of the most consecutive other primes

Here's a Python implementation of the Sieve of Eratosthenes: ...
0
votes
1answer
54 views
7
votes
3answers
96 views

RateBeer.com scraper

This was largely an exercise in making my code more Pythonic, especially in catching errors and doing things the right way. I opted to make the PageNotFound ...
1
vote
2answers
48 views

Inserting e-mail subscribers into MySQL

I'm new to Python and I am learning database connections from here. This is the code I am using to insert e-mail subscribers into a table: ...
5
votes
1answer
47 views

Simple, pythonic IRC interface

All of the other Python IRC packages I've seen out there are overly complicated for simple tasks, and they don't abstract away much of the complexity of the protocol and asynchronicity. I've taken a ...
-3
votes
0answers
14 views

WA for Codechef problem DOUBLE [closed]

My code gives the wrong answer (according to the judge) and I'm unable to figure out why. I just started solving the easy set of questions on CodeChef a couple of days ago. Link to the problem ...
4
votes
1answer
64 views

Generate sample coordinates inside a Polygon

I have a Polygon named as poly. I attempted to randomly select 5 coordinate points that lies inside the polygon. ...
3
votes
3answers
90 views

Summing over the values of a dict

I'm coming from the Java world and making my first steps on Python and see how good it is to express more with less code. I'd like to know if, via Python, the size of the following code could be ...
3
votes
1answer
60 views

Generate a random integer of length N with unique digits

The task is simple: given N, generate a random integer with no repeating digits. ...
4
votes
2answers
114 views

Algorithm for describing chess positions

I have an interesting problem with my chess application. The application reads PGN files, and at any time while viewing a game from the file, the function below, when called, iterates over the ...
0
votes
0answers
38 views

Fastest computation of N likelihoods on normal distributions

In the context of a Gibbs sampler, I profiled my code and my major bottleneck is the following: I need to compute the likelihood of N points assuming they have been drawn from N normal distributions ...
1
vote
1answer
33 views
0
votes
0answers
34 views

Python script for CryEngine 3 assets

I'm currently preparing some basic code samples for a trainee position. I've formatted some of my older tools that I had previously written, but feel confident about. I would very much appreciate a ...
4
votes
1answer
29 views

PyMel / Python script for setting animation keys

I'm currently preparing some basic code samples for a trainee position. I've formatted some of my older tools that I had previously written, but feel confident about. I would very much appreciate a ...
1
vote
2answers
116 views

Sieve of Erathosthenes speedup

While reading HackerNews, I learned about a data set of the first 50 million primes. This would be a lot, but his website has disclaimer: n this directory I have the first fifty million primes in ...
3
votes
2answers
71 views

Binary to decimal number converter

Here I am doing some exercises for my studies with Python. This is a binary to decimal number converter (currently restricted to that). These are the very first steps, so there is no error handling. ...