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

learn more… | top users | synonyms

0
votes
0answers
7 views

Pick a column for each row by column-header name

I am parsing a table: |-------| |Bar|Foo| |-------| | 5 | 6 | |'f'|'g'| | 1 | 8 | |_______| I've tried a number of ways of writing a ...
2
votes
0answers
9 views

BK Tree implementation

I'm working on a system that can search for similar images. This involves being able to search by edit-distance, and as such I've implemented a special data-structure called a BK tree. Some notes ...
2
votes
0answers
17 views

Fast draw wxPython OnPaint

I have the following wx.Window: ...
2
votes
0answers
19 views

Python code to write simple VPK archive files

I'm new to Python, but have a lot of experience with C and C++. I would appreciate some feedback on my implementation of a packer for this archive format. Specifically, any feedback on how idiomatic ...
4
votes
1answer
50 views

Monte Carlo AI in 21 game

I am very interested in the Monte Carlo AI. I tried my best, still, this AI plays very badly. This code "works" in the meaning that it does not crash, but the quality of play is extremely low. Have ...
9
votes
3answers
517 views

Beginnings of a base-conversion game in Python

I'm pretty very new to python, so I thought that I'd write a game to teach me python and better teach me how to think in hexadecimal and binary. I'm starting off by writing a few functions to convert ...
3
votes
3answers
51 views

Padding a hexadecimal string with zeros

I'm given a hexadecimal number in string form with a leading "0x" that may contain 1-8 digits, but I need to pad the number with zeros so that it always has 8 ...
2
votes
1answer
54 views

Convert between two bases, each between 2 and 36

I'm doing some Python practice for fun and I wrote some code that converts between two bases. I'm thinking about expanding on this later, so the docstrings are pretty redundant from function to ...
0
votes
0answers
4 views

Plugins and exporting an API between python scripts [migrated]

I've got a python script, which should read a subdirectory and make all the scripts within it callable like this: python mainscript.py subscript arguments I've ...
4
votes
1answer
113 views

Sum of numbers which are not sum of two abundant numbers

The following program is a solution to Project Euler Problem 23. That problem defines an abundant number to be one whose sum of proper divisors is greater than it, tells us that all integers at least ...
2
votes
0answers
46 views

Merge sort in Python

I've written a implementation of a merge sort in Python. It seems correct and I have tested it with this: ...
0
votes
0answers
5 views

How to make a smiley face in Turtle? [migrated]

First time ever using Turtle. My assignment is to make a smiley face, any size and any position. I just can't get the mouth right because I really don't know what I'm doing. I've read quite a bit and ...
1
vote
1answer
29 views

Defining functions in Vigenere cipher

I'm trying to learn the process of defining/calling a (somewhat) complex function. I understand the main idea, and can do it on a small (simple) scale. A simple example: ...
3
votes
2answers
150 views

Generating character permutations

I want to generate a 'dictionary' containing all 8 character permutations of upper-case letters such that the output file looks like: ...
3
votes
2answers
53 views

Eurovision voting order

Part of the Eurovision Song Contest is the voting process to determine the winner of the contest. Each country gives between 1 and 12 points to its 10 most favorite songs. When all the points have ...
2
votes
2answers
62 views

Summing all parameters, except the last, which should be subtracted instead

Working on some python koans and got one which states: ...
2
votes
2answers
139 views

Function that takes an array of integers and returns that array rotated by N positions

Example: if \$N=2\$, given the input array \${[1, 2, 3, 4, 5, 6]}\$ the function should return \${[5, 6, 1, 2, 3, 4]}\$ Here is my code: ...
2
votes
2answers
41 views

Small CLI note manager and publisher

This is my first attempt at trying to make a CLI note manager, than can be easily published on the web. I have made one note and you can see it live here. I have added some comments, and placed the ...
-1
votes
0answers
17 views

Python Tkinter controlling flow using classes [on hold]

I have recently started learning Tkinter, which is my first experience of GUI programming. For my first project, I am trying to write a 'scrabble scorer' that I have already created as a console app ...
0
votes
1answer
30 views

Pythonic way to find index of a list using the sum of the list elements [on hold]

I'm trying to make a function that returns the index of the smallest element whose sum along all the elements to its left is bigger than a number x. How can I do ...
2
votes
1answer
56 views

Creating objects from parsed file

I'm newbie in Python but I want to know some tricks to make my code look cute. I know that syntax of Python allows to do this, but I don't know how. Suppose I have file with lines of format "x y z" ...
3
votes
1answer
41 views

Fast counting of interactions between groups given users interactions and groups assignments

Given: An array c that contains the group assignment of every user (c[i]=4 indicates that user i belongs to group 4) A matrix ...
3
votes
1answer
111 views

Find next highest number with the same digits

Question: Given any integer, efficiently find the next highest integer that uses the same digits. For example if the number is 15432, you should return ...
1
vote
1answer
43 views

Writing a Pythonic prime sieve

I'm practicing writing code less by brute force. I'd like feedback for writing a prime sieve more Pythonic, simpler, or more creatively perhaps. ...
1
vote
2answers
65 views

Enhance a Caesar cipher

I have just written a simple program to implement the Caesar cipher using lists. The program assumes the input will be all capital letters. I'm quite new to Python and am just curious of some more ...
3
votes
0answers
26 views

Calculating the distance squared between all vertex-pairs of a number of 2D polygons

I have implemented my code using Cython. It is the current bottleneck in my computations. There are two non-numpy functions involved: calculate_2D_dist_squared ...
2
votes
2answers
36 views

has_cycle in directed and undirected graphs

I wrote a program that can tell if a graph has_cycle or not. Can you please suggest more elegant and eloquent ways for this program? (Perhaps better ways to represent a graph with vertices and ...
-1
votes
0answers
36 views

Slot machine basic [closed]

So I made this amateur slot machine... Anything you think i should change? Or is there any bugs you might be able to find. Or if you can find a way to shrink the code yet get the same result ...
0
votes
0answers
52 views

Check if brackets are balanced [closed]

I'm writing a Python method which checks Python code, given as a string, for errors. One of the things I want it to recognize is mismatched brackets, IE, [} would ...
1
vote
2answers
63 views

Reverse Message Program

...
3
votes
5answers
195 views

Finding if a given number is in a given range based on a flag

Question Description: Given a number n, return True if n is in the range 1..10, ...
0
votes
1answer
41 views

Automatic password security test for WordPress

I was bored the other day and wrote the following little script to attempt to find insecure passwords for WordPress blog owners so they could be notified of how easy it would be to crack their WP ...
4
votes
4answers
78 views

Conversions calculator

I'm a student currently studying computing/programming at school and am a beginner and would like some help understanding how to shorten down my code. I know some basic Python and can program ...
-1
votes
0answers
30 views

Closest pair of points solved by sweep line

Can you please suggest more elegant and eloquent ways for this problem? (Perhaps better ways to represent a graph with vertices and edges?) Pair of Points problem is described here. ...
2
votes
2answers
36 views

Collatz Conjecture in Python

The Collatz's Conjecture states that any number can either be halved (if it is even) or multiplied by three and added one to (if it is odd) and eventually reach 1. I was wondering if there was a more ...
3
votes
1answer
69 views

Validating and averaging student grades

I have myself a little challenge tonight. I've tried to come up with the shortest code for the problem below (the code is pretty self explanatory, except ...
0
votes
0answers
55 views

Skyline problem solved by sweep line

Can you please suggest more elegant and eloquent ways for this problem? (Perhaps better ways to represent a graph with vertices and edges?) Skyline problem is described here. ...
3
votes
1answer
64 views

Simple Django website with no authentication. For auth/testing tutorial — Model, model-tests, urls.py, and settings.py only

I am writing a simple Django project which has no authentication at all. It's going to be used as the basis of a tutorial I'm writing, on the full authentication lifecycle (create account, login, ...
6
votes
2answers
194 views

Command-line-based capacitance decoding

I am an amateur programmer and have just written a simple Capacitor Identifier mostly to practice. I have not had many people review my coding and thought this would be a good time to start. It is ...
-4
votes
0answers
18 views

Undefined Function? [migrated]

I am not sure why I am getting an error that game is not defined: ...
9
votes
8answers
2k views

Find the nth prime between 1 and 1,000,000 in under 3 minutes - follow-up

Previous question: Checking for the nth prime number between 1 and 1,000,000, must compute 1,000,000th in under 3 minutes My mission is to find the nth prime number, based on user input 1-1,000,000. ...
0
votes
0answers
38 views

Longest increasing subsequence and common substring

I wrote a program that computes longest increasing subsequences and common substrings. Can you please suggest more elegant and eloquent ways for this program? (Perhaps better ways to represent a ...
4
votes
1answer
71 views

Polyalphabetic cipher

I am trying to write the simplest to undestand code possible, each function has documentation and examples and I tried to use the best style possible. ...
4
votes
2answers
243 views

Finding 10-unique-digit number with i-first-digits divisible by i

I was posed this question by a friend: I am a natural number written with 10 different digits such that for all \$i ∈ {1, . . ., 10}\$ the number formed by my \$i\$ first digits (from left to ...
3
votes
1answer
33 views

Backup files script

I'm creating own script for backup user's directories. CentOS 6.5; Python 2.6. Directories looks like: ...
2
votes
0answers
43 views

Speed up a function using NumPy

I have a function written in Python 2.7 that I call several times in a program. This function is rather slow, and I'd like to rewrite it in NumPy. However, I don't know how to do it. I basically have ...
8
votes
7answers
1k views

Checking for the nth prime number between 1 and 1,000,000, must compute 1,000,000th in under 3 minutes

My mission is as the title states. Here is the original code, before optimizing slightly (but still not enough). Revised code is in my answer, and it still needs work. Also, I want to write this ...
4
votes
3answers
301 views

Simplify a fraction

I have been learning Python for a while (my first programming language) in my spare time. Since it's been 20 years since math class, and I didn't get very far with that, I just brushed up on ...
9
votes
1answer
102 views

Modular Exponentiation

I want to solve the following for \$x\$ (in Python): \$x^{101} = 8765 \ (\mod{9691573})\$ I coded this: ...
0
votes
4answers
35 views

Speeding up script for processing three huge files

I have three huge files I need to process in order to rearrange the data contained within. The first file is a list of English example sentences (468,785 lines long). A typical line from this file ...