Questions tagged [python-3.x]

Python 3 is the latest version of the Python programming language and was formally released on December 3rd, 2008. Use this tag along with the main python tag to denote programs that are meant to be run on a Python 3 interpreter only. Do not mix this tag with the python-2.x tag.

Filter by
Sorted by
Tagged with
4
votes
1answer
53 views

FIrst time trying tree classifier in python

Recentely I have started teaching myself some basic AI concepts and this was my first attemp at using a random forest in order to classify the iris data set. It would be great if anyone could give me ...
2
votes
1answer
68 views

Twelve Days of X-mas in Python

Printing the lyrics of "Twelve Days of Christmas" seems to be a fairly popular programming challenge. As I've successfully attempted it, I was wondering if the code can be simplified even further (...
3
votes
2answers
73 views

LeetCode #494: Target Sum (Python)

Below is my solution to LC #494: Target Sum (given a list of numbers and a target integer, find out how many different ways the numbers can be subtracted from the total sum to result in the target sum)...
2
votes
1answer
43 views

Populate list with Excel range and keep formatting

I have written a Python programme that takes data from Excel sheets and adds this data to new .DAT files. I use win32com.client because the Excel sheets will ...
2
votes
2answers
52 views

UI code for save editor

I'm wondering what I could do to improve the function that handles initializing the UI. I think it looks disgusting. Any ideas on what I could do besides splitting the code up into multiple functions ...
5
votes
2answers
641 views

Writing 1.5 million rows in a file

I am generating SQL statements (of MySQL format) and writing into a file to create 10,000 tables. Each table contains 5 columns with 1.5 million rows of data in each column. I generated these data by ...
2
votes
1answer
58 views

Multithreading to process requests and save results in python

I was presented with a task to come up with a script that generates a CSV with POSTAL codes via bruteforce (I'm in Brazil, so that means CEP to us). Points to note: I'm using an external library, ...
1
vote
1answer
63 views

Work command handler for an economy system

I have been working on this code, which is the part of an economy system that handles the work command. This lets the user pick a role and if they have enough level then they will get it by updating a ...
2
votes
3answers
106 views

Counting numbers that are divisible by 3 and can be produced from the digits of a given number

I'm trying to solve this problem from codewars. Problem Given a certain number, how many multiples of three could you obtain with its digits? Suppose that you have the number ...
2
votes
1answer
30 views

Flattening XML and selecting nodes based on input to convert to CSV

I have some XML that I want to flatten based on its XPath. The task is to acquire certain nodes that are passed as input. That said, I have to get to parent nodes and look for nodes that might be part ...
2
votes
0answers
41 views

Motor control PLC in Python

Project description We have different types of devices like sov, motor, analog, digital, control valves etc. Each type of device has 100 items. Now our software continuously monitors with the PLC to ...
2
votes
1answer
30 views

Python task runner with asyncio

I'm trying to a write super simple task runner with asyncio. Basically, my goal is to run 100 requests to google as tasks, whilst also being be able to handle tasks being added at a later time. <...
5
votes
1answer
44 views

Stack Exchange graph data - helper modules

Building on previous reviews Whilst not an iterative review I have tried to follow the advice provided to some of my older questions: KISS, in some of my previous questions I've over complicated the ...
3
votes
2answers
92 views

Challenge: MORSE_CODE.PY

Converting words to morse code and vice versa using dictionaries and that's it. ...
2
votes
1answer
71 views

USACO Arithmetic Progressions

The problem I'm solving is: given a length of an arithmetic progression, and a limit to the terms (see below), find all progressions that work. All terms of the progressions must be of the ...
5
votes
4answers
449 views

Counting consonants and vowels

I'm new to Python and want to develop good habits at the beginning. This class takes a string, and then counts the number of vowels and consonants in the word(s). Any advice on how to improve? <...
3
votes
2answers
35 views

Temporary modifying env variables with context manager

One function of a program I'm working with benefits from using all available openMP threads. The rest of the program has issues with the env variable OMP_NUM_THREADS...
4
votes
2answers
99 views

“Tic Tac Toe” game in Python

I'm relatively new to Python. Here is a Tic Tac Toe game I've created in Python: ...
3
votes
1answer
93 views

Revised text adventure game with a war theme

The actual code layout of a text adventure. This text adventure is a much-improved sequel to the first code. It is three times as long but three times more efficient. The setting is based on the ...
26
votes
5answers
5k views

A first “Hangman” game in Python

I am new to Python (it's my first language), been coding for a couple of weeks now. I have already made a couple of simple scripts to download and manipulate some financial data, but lately I thought ...
2
votes
0answers
92 views

Minimum number of swaps for two 2D arrays to make the first one identical to other

Bit Swapping You’re given two binary matrices, m rows and n columns. Both matrices have the same size i.e. same number of rows and same number of columns. Each cell is a bit either 0 or 1. You need ...
1
vote
2answers
127 views

Is it worth to compromise on speed to follow PEP 8 guidelines? [closed]

I have this long line of code: enc = encoder.predict(np.array([data[stock][4*i:4*(i+30)] for i in range(lens[stock]+days-30)])) The problem is, the number of ...
2
votes
0answers
48 views

Find text between two strings in data [closed]

I download a page to get it's source code. I then extract the first segment of the page that is between two strings that appear in the source code more than once. How can my code be improved? ...
3
votes
2answers
53 views

Reading serial data from Arduino into Python every 100 ms

I am trying to send data from an Arduino into Python via USB every 100 ms. What improvements can be made to my code? I feel like it is kind of bloated and can be better written, but I'm not sure which ...
4
votes
2answers
108 views

Converting a set into a string

The input is a set of alphabets. The output is a string of 32 in length. For any letter in the set if it is preceded by a '¬' we replace the n-th character in our output string with '0', such that n ...
4
votes
3answers
151 views

Fast way to calculate source response using Green's function

I am a newbie in the scientific computing in python. The function I am trying to calculate is the response of the wave equation for a given source term (For reference, See: Equation 11.67 in https://...
6
votes
4answers
102 views

Calculate the number of primes in a range

I wrote some code to return how many prime numbers are in a specific range and what they are. It also tells you whether the number of primes is also a prime! I feel like this seems like a fairly long ...
12
votes
2answers
2k views

Script that helps people make better choices

This is a "Help me make a choice" script where the user can input two options and then, based on the (3) reasons why they are good options, and the reasons weight the script will tell you which option ...
6
votes
2answers
93 views

Duplicate File Finder in python

I just started learning python yesterday, I have prior experience of C++. So I think I am able to get most of it pretty fast. I wrote a duplicate file finder for testing and practicing. Can you guys ...
-1
votes
1answer
69 views

Champions League Simulation [closed]

Here is my first attempt at creating a full Champions League Simulation, including drawing the groups and subsequent games and playing all matches. The code is very, very long and I am sure there must ...
3
votes
1answer
53 views

A persistent file system operations queue using sqlite and JSON text fields

I want to implement a persistent queue for file system operations (copy, delete, move) that needs to be process and thread safe. The module will be used by a daemon (called ...
5
votes
1answer
55 views

Interactive folder files organizer (Alpha-numeric and type) for macOS / Linux in Python

A simple interactive Python script for organizing messy folders on the computer, supports macOS and linux but not windows. The mini-program has the following features: Creation of Alpha-numeric (A-Z /...
2
votes
2answers
153 views

LeetCode #1120 Maximum Average Subtree (Python)

This code snippet shows 2 common patterns I see a lot in Python that I don't really like: Arbitrarily-named, narrowly-scoped recursive function Inappropriate data type (in this case, an array ...
2
votes
1answer
62 views

Remapping property IDs when inserting CSV data to a database table

My code is functioning the way I'm expecting, with the if. However, it is not pythonic to me, and that bugs me. The multiple if in the code below are supposed to ...
5
votes
2answers
107 views

Project Euler # 62 Cubic permutations in Python

The cube, 41063625 (\$345^3\$), can be permuted to produce two other cubes: 56623104 (\$384^3\$) and 66430125 (\$405^3\$). In fact, 41063625 is the smallest cube which has exactly three permutations ...
0
votes
1answer
64 views

How to find the common factors of 2 numbers [closed]

Print the number of common factors of a and b. input > 10, 15 Output > 2 The common factors of 10, 15 are 1 and 5 My code ...
2
votes
1answer
69 views

Exporting data from PostgreSQL as CSV to S3 bucket

I have a general question regarding DRY. As you can see there are several parts such as io.StringIO(), csv.writer, ...
4
votes
1answer
52 views

Command line utility to convert image formats of photos

Below is some code for a basic command line utility to convert image formats of photos. I'm wondering how any part of it might be written with better style, i.e. how it could be neater, clearer and ...
2
votes
1answer
56 views

Functional n-queens

Following the book "Structure and interpretation of computer programs" I have tried to implement a functional solution to the problem of N-queens (implemented by the function ...
4
votes
1answer
73 views

Tab 2 spaces convertor (for markdown)

This program converts glob files' tabs to spaces. There is a special case to ignore content inside triple back ticks. Example usage is ./tab_2_spaces.py *.md Main ...
2
votes
1answer
39 views

Comparing web-scraped data from several sports betting APIs

I have written a python script that requests information from several Sports Betting API's, processes and standardises the results into a dictionary, Matches items between dictionaries and then ...
10
votes
4answers
3k views

Sum Square Difference, which way is more Pythonic?

I'm using python 3 and I am creating an algorithm to find the sum square difference for the first 100 (or 1 to x) natural numbers. This happens to be project euler problem 6 if anyone is wondering. I'...
0
votes
1answer
49 views

String manipulation in Python

I have this very ugly piece of code which runs ethtool and then parses the output (Lilex is just a static class encapsulating subprocess and is not relevant to the ...
0
votes
2answers
416 views

Income tax calculator [closed]

I've just started coding and have written a program to calculate your tax to be paid. Is there anywhere where I can improve this? ...
-1
votes
1answer
57 views

Python 3 code for a binary search tree [closed]

I am working on a python3.6.5 question about BST: Binary search tree (BST) is a binary tree where the value of each node is larger or equal to the values in all the nodes in that node's left ...
-3
votes
1answer
66 views

Project Euler #5 Optimized

I have seen multiple questions on this problem but none seem to answer my specific question. To start, the basic question is asking to find the smallest number that is divisible by numbers 1 to 20. ...
5
votes
2answers
103 views

Bracket balance checker in Python

Implement a feature for a text editor to find errors in the usage of brackets in the code. Input: sorted(list(zip(a, b)) Output: False Input: ([{}, {}]) Output: True Here's my implementation in ...
14
votes
5answers
3k views

Markov-chain sentence generator in Python

I wrote a Markov-chain based sentence generator as my first non-trivial Python program. I mainly used C before, so I probably have ignored a lot of Python conventions and features, so any advice would ...
3
votes
0answers
65 views

JSON to CSV in python using json.loads and json_normalize

I am trying to convert a JSON file to CSV format using Python. I am using the JSON.loads() method and then using json_normalize()...
4
votes
3answers
390 views

Project Euler # 15 Lattice paths in Python

Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner. How many such routes are there through a 20×20 ...