Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.
0
votes
0answers
5 views
find median of two numbers
Working on this problem and post code, my question is whether it is safe to change this line of code
j > 0 and i < m and B[j-1] > A[i]
to
...
4
votes
0answers
18 views
Creating a count inversion array of an unsorted array of unique integers
Given an array:
arr = [2,3,1,4]
I could write a count inversion array such that counting all numbers n2 after a certain ...
0
votes
1answer
28 views
How to avoid slow triple for loop in python?
I am writing a triple for loop in python. Since the data set is larger, it takes more than 1.5 hours to finish. Is there any fast way to avoid the loop?
...
1
vote
1answer
14 views
Noughts & Crosses
This is my first ever program on my first language, Python. I wanted to know how I could improve my writing style.
...
1
vote
0answers
14 views
Python CSV reader
I have a function that pulls data from a file or string literal in my case and returns them in either a list or a dict.
My ...
0
votes
0answers
21 views
Arithmetic quiz
The code below is an arithmetic quiz that saves a students last three score to their name and allows their teacher consequently to sort their scores in a variety of different ways.
However, my ...
-2
votes
0answers
7 views
convert between hex, ascii and decimal [on hold]
I frequently need to convert between decimal, hex and ascii characters. I wrote a Tkinter program to do the conversion, mostly, but I ran into a bit of a problem. If I convert random hex bytes into ...
2
votes
1answer
20 views
Python - insertion sort
Series post - I am reading through Introduction to Algorithms, 3rd Edition implementing each algorithm as I read them.
Pretty basic insertion sort. Only considering numbers initially - how could I ...
0
votes
2answers
35 views
-1
votes
2answers
40 views
Maths quiz with difficulty levels and a score database
How can I make the saving to the dictionaries more efficient as well as making my overall code more efficient?
...
-1
votes
1answer
108 views
On Finding Coin Jams
The problem can be found here and is essentially asking us to generate J many numbers containing N many digits, where these digits have to be either 0 or 1. The catch is that the these numbers that we ...
1
vote
2answers
19 views
Inputting multiple strings and finding their length
I need to find the length of elements within a string and return it to the user.
What is the best way of simplifying this code to make the amount of string lengths equate to user input? Also, how can ...
0
votes
0answers
18 views
Python for HPC: Parse file, generate statistics, record output
I have a program which is designed to be highly parallelizable. I suspect that some processors are finishing this Python script sooner then other processors, which would explain behavior I observe ...
-4
votes
0answers
12 views
python decimal to quad ip script fails [on hold]
All - Im attempting to create a small decimal to quad ip script to help me convert some decimal ips. I keep getting an error when getting the list of IPs from file. The the IPs do print out when ...
3
votes
1answer
26 views
3
votes
0answers
37 views
OAuth2 Implementation
I am trying to implement a oauth2 service. I am not planning to use it anytime soon (like will write unit tests). This is my fun project I do to practice. I have used the python_jwt library to create ...
1
vote
1answer
56 views
vlookup in python
I wrote a little function that does, I think, what the Excel function does:
Given a value and a table (matrix), search for the row that has value closest to but not greater than the given value. ...
-1
votes
0answers
19 views
Guidelines for returning None vs. raising exceptions for Python string-validating functions [migrated]
Let's say we have a function that checks if a given pattern occurs in a string. The default behaviour is that if the pattern matches, then it returns the pattern. So far so good but what is the ...
2
votes
0answers
39 views
UDP server for a multiplayer game using socketserver
I am making a multiplayer platforming game, and currently there are server performance issues once I have about 7+ clients connected. I was told earlier last week that I should investigate ...
0
votes
0answers
17 views
Lo Shu Magic Square - checking for diagonals [on hold]
I am having difficulty with a Lo Shu Magic Square assignment. Here is what I have
...
0
votes
0answers
41 views
Testing current, new or friends firms as max output and least effort
I have a firms dynamics program (fully based on Axtell, 2013) that runs very fast, except for the function below. Could anybody point to more pythonic ways to write this function? (I use numba, tried ...
4
votes
1answer
49 views
Fuzzy Octo Guacamole interpreter
This is my code that interprets my own golfing and esoteric language, Fuzzy-Octo-Guacamole.
It has 2 stacks to store information in, and various operations can be performed on each stack, or both at ...
-1
votes
0answers
25 views
Alpha-Beta Pruning isn't working well [closed]
I'm creating an artificial intelligence in Python for Othello (10*10) using alpha-beta pruning but it doesn't seem to work well. It often sends bad moves while the evaluation funtion is a good one. ...
1
vote
1answer
27 views
Store and output hard-coded relationships among hosts
The following code has begun to smell, but I have not yet decided with what to replace it, other than, obviously, a database.
I made a very unsatisfactory workaround for my attempt to make ...
1
vote
1answer
38 views
Multi-threading upload tool
We have about 14G files and each is about 150k.
I'm writing a script to upload them to Azure Blob storage and would like to run an upload() function (each with own ...
2
votes
4answers
511 views
regex to extract version info
I have written a small Python function to extract version info from a string.
Input is of format:
v{Major}.{Minor}[b{beta-num}]
Eg: v1.1, v1.10b100, v1.100b01
Goal is to extract Major, Minor and ...
0
votes
1answer
17 views
Export lists to CSV in columns with header Python [closed]
I've scoured stack exchange to try and get my script to work. I'm trying to export my 3 lists to a csv file, I want each of the lists to be in 3 separate columns with a header for each list. I know ...
2
votes
1answer
89 views
Loading data from a text file into the database as fast as possible
I'm building a Django (1.8.12) application that parses a .bc3 file (Standard Interchange Format for Databases of Construction and Real State) and loads all the data into the database (PostgreSQL ...
4
votes
3answers
518 views
Eval is evil: Dynamic method calls from named regex groups in Python 3
I'm working on a simple dice roller for a Python IRC bot. The particular game this roller is for uses six different kinds of dice, which I've defined using a simple base class, and created six ...
2
votes
1answer
38 views
Python Tkinter Game - Treasure Hunt
I used to write a bit of BASIC years ago, and recently found an old book called "Fun Mathematics on your Microcomputer" with some mathematical games in. I'm learning Python and have tried to implement ...
3
votes
2answers
30 views
Tic Tac Toe “Cats Game”/End Game
I have made my first game in Python.
My program can determine when there is a winner, however I am unsure what to do if the board is full and there is NO winner (a cats game).
...
-4
votes
0answers
22 views
Using Dictionaries to count first letter in a string [closed]
I've been working on a dictionaries exercise in Python, and I'm fairly new to the language and programming in itself. I've been trying to take a string or list of strings and have my code compare the ...
0
votes
2answers
39 views
Minesweeper, python Tkinter, Checking close by tiles
Is there any smart way to compress the following code:
...
7
votes
1answer
63 views
Simple labyrinth
I'm making a a simple labyrinth. I want to make it so that I could hit a wall, and if I did hit the wall, I wouldn't cross it.
...
3
votes
1answer
56 views
Generating a maximal geometric progression of integers
I'm working on a program that generates a maximal geometric progression of at least 3 integers when given a number that the greatest value shouldn't exceed.
My current code works, and it's quick(ish) ...
-1
votes
2answers
30 views
Primitive Twitch.tv IRC Chat Bot
So currently I have this basic little chat bot that can read commands and can timeout users if their message contains a banned word or phrase. I was wondering how I can improve on this bot to be able ...
1
vote
1answer
16 views
Twitch client that notifies me when a followed streamer comes online
I've been writing code for a little while but I'm a little slapdash. I'd like to get better so I've been having a glance at best practices, other peoples code and reading a whole lot. I'd appreciate ...
7
votes
3answers
43 views
From Q to compiler in less than 30 seconds
As an adjunct to From new Q to compiler in 30 seconds, I've created a Python script to automatically download the markdown from any question on Code Review and save it to a local file using Unix-style ...
-1
votes
0answers
11 views
mysqldb inserting list of values into a table [closed]
I am trying to pass some values from a list into an insert statement and thought it would be straightforrd enough but I find myself wasting far too much time on this:
please could eomeone explain ...
3
votes
1answer
60 views
Dijkstra's algorithm: traditional and bidirectional in Python
I have translated Dijkstra's algorithms (uni- and bidirectional variants) from Java to Python, eventually coming up with this:
Dijkstra.py
...
1
vote
1answer
25 views
Using Pexpect for communication between multiple programs via I/O
I have a Python script that runs three compiled programs and makes them communicate via standard I/O. This is my first time using pexpect. My program runs very ...
0
votes
1answer
34 views
Simple weighted directed graph in Python
I have this simplistic Python class for representing directed weighted graphs (digraphs for short):
Digraph.py
...
3
votes
1answer
23 views
Get argument as unicode string from argparse in Python 2 and 3
Code from my last project, that has to work on Python 2.7 and Python 3.
I want to get a path as a unicode string from argparse:
...
-3
votes
0answers
16 views
6
votes
2answers
176 views
Divisor game cheating aid
This code outputs the smallest number with more divisors than the input:
...
0
votes
1answer
37 views
Match two dictionary keys efficiently in Python
I have two dictionaries that I need the keys to match and if they match i will get the value of the first dictionary and then get the value of 2nd dictionary and build a new dictionary out of those.
...
1
vote
0answers
27 views
Breadth-first search: traditional and bidirectional in Python - follow-up
I have refactored the version of the previous (and initial) iteration according to the answer by alexwlchan. As a reminder, this snippet compares breadth-first search against its bidirectional ...
2
votes
3answers
138 views
Search in a big dictionary Python
I have a big Python dictionary with more then 150,000 keys every key has list value. This dictionary contains infinitive words as key and all grammatical forms of these words as values:
...
2
votes
2answers
53 views
Python number guessing game
I'm a PHP Developer. I'm trying to learn Python. So I tried to create a simple game, a Number Guesser.
I tried to comment out as much as possible without making super obvious comments.
I also made ...
1
vote
1answer
58 views
Checking whether a host has a second-level domain from a list
I have an url and need to check whether it has some second-level domain (SLD) from a list. For example for SLD foo.com I need to ...