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

learn more… | top users | synonyms

5
votes
0answers
42 views

Implementing Karatsuba Multiplication Algorithm in Python

I am trying to implement Karatsuba multiplication algorithm for binary (base 2) numbers. A requirement is that the intermediate / final results must also be in binary so as to assist in educative ...
12
votes
4answers
904 views

Simple random number generator

I have been wanting to learn programming for some time now and decided to really give it a shot today. I have edited and read lots of things in Java to fix small issues but never written from scratch. ...
4
votes
1answer
27 views

Filewatcher compiler for watching different files

I'm trying to create a filewatcher program that can watch different files. The files might have subfiles that are being imported into the main file, which is being represented by the file object. I'm ...
5
votes
0answers
52 views

Improving performance for Codility max slice swap problem

Problem Description: Find the maximum sum of a compact subsequence of array elements after performing a single swap operation. Solution: ...
3
votes
1answer
32 views

Is there a better way to catch API changes?

I'm using the Google Spreadsheets API to access several spreadsheets and put their contents in a database using Flask and SQLAlchemy. Each run deletes the contents of the database tables and ...
3
votes
2answers
39 views

More efficient conversion of tab-formatted nested data structure to json

I have data that looks like the "Input" below and need to convert it into JSON. My solution works by parsing the text to find a level for each data point. Then I use a recursive structure to build a ...
6
votes
1answer
188 views

Basic BrainFuck interpreter

I was bored, so I wrote a BrainFuck interpreter in Python. It essentially takes input for the amount of cells, then parses the inputted code through a series of if ...
5
votes
1answer
43 views

Is it pythonic to create side effect inside list comprehension?

I am trying to generate a pascal triangle table in python3. I started to like using this following pattern when dealing with 2D arrays. Generate a list of valid indices Use a function that work with ...
13
votes
1answer
96 views

Python - Minesweeper

I'm new to Python (and generally to programming), and I have recently written this Minesweeper game: ...
4
votes
2answers
31 views

List Comprehension in Pythonic answer to LPTHW ex48

I'm not really seeing any use for a generator here, unless there's some way to hook a generator into a language dictionary. But in the following code, the longhand version of the ...
3
votes
1answer
32 views

Removing of star-args [on hold]

I have such functional code: ...
3
votes
1answer
108 views

Optimizing and clarifying nested list appending

I have such part in my script, how can I optimize such parts? I don't want to use many local variables. ...
0
votes
1answer
19 views

Saving a webpage to text file [on hold]

I'm trying to save a webpage as text file, using the following function: ...
4
votes
2answers
72 views

Getting the unique factors of a number recursively

I have written the below code to get the unique factors. Please offer suggestions for better results. ...
1
vote
0answers
22 views

“Transparently” converting the output to an e-mail message?

I recently wanted to write a regression testing script that produces a report that looks like this: ...
9
votes
2answers
166 views

Calculating the checksum digit with the Luhn-algorithm

I'm doing some exercises in Python and this one is about using the Luhn-algorithm to calculate the checksum digit in Swedish personal identification numbers. The description is the same as this ...
0
votes
0answers
17 views

Optimizing max similarity for WSD in python

I have a library for simple Word Sense Disambiguation (WSD), https://github.com/alvations/pywsd But i have a function for WSD based on the sum of maximum similarity score for every word. But it's a ...
1
vote
0answers
16 views

Speed up projection of a bipartitie network for a big file using NetworkX and Pandas

I have a pretty big file (3 million lines) with each line being a person-to-event relationship. Ultimate, I want to project this bipartite network onto a single-mode, weighted, network, and write it ...
6
votes
2answers
178 views

Blackjack game with classes instead of functions

To try out the concepts and tools I've been learning, I decided to write a Blackjack game. I wrote it entirely with functions, so it hasn't helped me at all with the concept I really lack ...
5
votes
2answers
43 views

Simple python script to shorten URLs in specified text files

A recent question inspired me to write a script for this task: Shorten URLs in specified text files using googleapis.com Handle multiple URLs, whether on the same line or multiple lines The ...
3
votes
2answers
39 views

Convert international datestring to ISO-format

The function below takes a datestring in the form d-mmm-yyyy and converts it to ISO date format (yyyy-mm-dd). Delimiters may be hyphen, space or /, and Dutch or ...
3
votes
1answer
30 views

Connected components algorithm does not scale past 10,000 nodes

I found a connected components algorithm posted here on SO and modified it for my own purposes. It runs well for small input sets, but doesn't scale as well as I would like. The largest set I've ...
0
votes
0answers
15 views

Getting a list of all fines in a local disk

I wanted to get a list of all files in a local disk like C:\, so I wrote the Python script below to check the performance: ...
6
votes
1answer
60 views

Chat using commands

I have been learning Python and was trying to make a chat system which can be run by commands. This is my first attempt to write the code. Does this make sense or is it wrong usage of classes? There ...
3
votes
2answers
56 views

Codility Frog Jump solutions

Problem details from Codility: A small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position greater than or equal to Y. The ...
7
votes
2answers
65 views

Parse HTTP header using Python and tcpflow

I wrote a program that reads a pcap file and parses the HTTP traffic in the pcap to generate a dictionary that contains HTTP headers for each request and response in this pcap. My code does the ...
5
votes
1answer
61 views

Moving the player across an ASCII art “world”

Wow, this one is definitely going to need some improvement. So, just for fun, I decided to make a program where the player moves across a 2-dimensional ASCII-art map. If the player types something ...
5
votes
1answer
60 views

Interpolate then maximize

I need to optimize $$ \max_{a',\ m'} f(a, m, e, m', a') $$ I have approximated \$f\$ with a grid \$F\$ — it has shape \$(nA, nM, nE, nM, nA)\$. Now, I want to interpolate over the last two ...
3
votes
1answer
145 views

Moving a rover and receiving current coordinates

I made a little text-based game where you move a rover and it gives you the current coordinates. You can essentially move around a 1000x1000 grid, and get output into ...
0
votes
0answers
34 views

Command line multipart file downloader using requests

The code below downloads file in multiple chunks if split is set to some number, however there is a limit to maximum possible splits defined below by maxSplits if ...
5
votes
1answer
58 views

Efficiently matching IP addresses with a list of CIDRs

I am using Python3 to extract some information from a dictionary that contains 10k of CIDRs, but the running time is pretty long. Here is my purpose: I have a dictionary of CIDRs (10000) and a list ...
6
votes
3answers
275 views

Game inventory system

I've been trying to figure out the best way to create a inventory system in Python. I like the way this one works but what I was wondering was if there was a better way to write it. ...
6
votes
2answers
69 views

Printing inputted, largest, odd integer

The program asks the user to input 10 integers, and then prints the largest odd number that was entered. If no odd number was entered, it prints a message to that effect. ...
8
votes
1answer
77 views

Split large file into smaller files

I recently suggested this method for emulating the Unix utility split in Python. Is there a more elegant way of doing it? EDIT: Assume that the file chunks are too large to be held in memory. Assume ...
7
votes
2answers
340 views

Dictionary of attributes and values

In the code below, I have a dictionary of attributes and values. I am checking to see if the value if an attribute is True, and if so adding the attribute to a list for later processing (it becomes ...
2
votes
1answer
80 views

Painting Fences - optimize for faster performance

I am attempting this problem at Codeforces. I'm stuck as it gives a time limit exceeded error for large inputs though the logic I followed is similar to that of the editorial. I'd be grateful for any ...
2
votes
1answer
88 views

Mutations and Combinations

I have recently answered one question on Stack Overflow. Problem statement: Input sequence: PEACCEL User mutation input file: ...
0
votes
1answer
44 views

Performance issue with conditionally removing keys from a dictionary [closed]

I'm new to Python (2.7 Spyder). My code takes a long time to execute, and seems overly complicated. I'd like to use the range function but it isn't behaving as expected so, I'm using a comparison of ...
1
vote
0answers
55 views

Questions regarding the use of Requests Futures for accessing REST URLs

This is a much simplified version of the real code focusing just on the handling of Futures from Requests Futures. I have a few questions: I had to implement my own version of ...
0
votes
1answer
32 views

Using Comprehensions to Handle a Large Dataset in Python 2.7

I have a Python 2.7.6 script parsing large files (~60MB to ~2GB) containing lines of the following format: componentA componentB < floating point value > My goal is to sum the floating point ...
1
vote
1answer
42 views

Convert 2D list to dict of list of index

I have a 2D list like this: ...
5
votes
5answers
97 views

Improving efficiency for two sum

I am trying to solve this problem: Given an array of integers, find two numbers such that they add up to a specific target number. and this is my strategy: For each ...
7
votes
2answers
125 views

Displaying a scrolling stock exchange ticker in a window

I've written my first OOP program (194 lines including docstring and comments) in Python that uses Tkinter as GUI and Threads. The program shows a window and displays a scrolling stock exchange ...
0
votes
1answer
42 views

Multiprocessing basics in Python [closed]

I am trying to learn how to incorporate multiprocessing capabilities into my Python code. After reading through the documentation and several tutorials, I think I have an understanding of what my code ...
1
vote
0answers
28 views

Wrapper for database queries

I had a written code in Python, which works with a database and selects information. Every function in my class creates a session and executes some queries (their quantity varies). Also, each such ...
3
votes
1answer
55 views

Is this escape unescape function pair correct?

Is this example of an escape - unescape function correct? ...
1
vote
2answers
49 views

Binary Insert Method - handling edge cases

I've created a function that uses binary search to insert an element into an array (similar to this question). I haven't benchmarked it, but based on my knowledge it should get \$O(1)\$ in the best ...
0
votes
1answer
51 views

Faster way to parse file to array, compare to array in second file, write final file

I currently have an MGF file containing MS2 spectral data (QE_2706_229_sequest_high_conf.mgf). The file template is here, as well as a snippet of example: ...
2
votes
2answers
52 views

Django Custom Decorator for user group check

I wrote a custom decorator to check whether user is in particular group of not. Please provide the feedback on optimizing code. I currently moved from Java to Django-Python so I wasn't able to ...
-1
votes
0answers
79 views

Game of hog in Python

Below is the problem statement for Hog: In Hog, two players alternate turns trying to reach 100 points first. On each turn, the current player chooses some number of dice to roll, up to 10. She ...