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

learn more… | top users | synonyms

2
votes
2answers
16 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 ...
0
votes
0answers
28 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
94 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
36 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
25 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
148 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
49 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
53 views

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

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

Correcting user input to meet a specific requirement for Hangman [migrated]

I need the user input to only equal 1 character but there is a bug in the code that lets me enter more than one character at a time. I need to be able to prompt the user to say you can only enter one ...
2
votes
2answers
136 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: ...
1
vote
2answers
37 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
15 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
28 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 ...
0
votes
1answer
41 views

Creating objects from parsed file [on hold]

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
39 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
110 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
36 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
64 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
23 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
35 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
34 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
191 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
39 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
73 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
29 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
68 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
53 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
59 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
193 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
36 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
70 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
41 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
299 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
101 views

Modular Exponentiation

I want to solve the following for \$x\$ (in Python): \$x^{101} = 8765 \ (\mod{9691573})\$ I coded this: ...
0
votes
4answers
30 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 ...
5
votes
1answer
33 views

Python DictionaryTagger class takes too long to initialize

With big inspiration from code from different webpages, I have created this DictionaryTagger. My problem is that it takes around 2 sec. to initialize the taggers / ...
1
vote
2answers
80 views

“Guess My Number”, Alternative Edition

This is an alternative edition of a game I modified the code for. See: Guess My Number, Classic Edition I seek advice on best practice. Tips, tricks, and suggestions, all welcome: ...
5
votes
2answers
58 views

Making user menus in a text-based game

I'm new to Python and programming in general, but I'm making it work. I have this little game I've been working on as a learning exercise and I'm a bit concerned that I'm using far too many ...
-1
votes
2answers
99 views

Rewriting an ugly function

I have been recommended on stack to rewrite the function, but it does get the job done. Can I improve the efficiency or readability? ...
5
votes
1answer
54 views

Python wrapper for official Hacker News API

Since Hacker News launched their official API, I started working on Python wrapper for it. API v0 is fairly simple, you send a GET request with hacker news story's ID or user id, it returns data in ...