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
2
votes
1answer
30 views

IPython - Clipboard Extension

I often copy things from my terminal to other places (like Discord), and to make my workflow even easier I decided to use the IPython API to make an extension that has two magic functions ...
1
vote
3answers
58 views

Python - Making A Valid Date Checker - using Regular Expressions

Date Detection: Write a regular expression that can detect dates in the DD/MM/YYYY format. Assume that the days range from 01 to 31, the months range from 01 to 12, and the years range from 1000 to ...
1
vote
2answers
55 views

Python - Predicting the probability of 6 Heads or Tails in a row from a set sample size

I'm wondering whether there is a way to make this even more efficient or reduce the number of variables. ...
8
votes
2answers
389 views

Alphabet Rangoli Challenge

The question is about printing alphabets in a rangoli pattern of size/dimension input by the user. Example: ...
0
votes
1answer
45 views

Exercism: Class representation of a matrix in Python

The task is to represent a Matrix as a class and to instantiate it from a string such as "1 2 3 4\n5 6 7 8\n9 8 7 6" The class must provide methods for ...
2
votes
1answer
34 views

What is the most optimal way to concat XML files as one large string/text file?

Python3 - Recursive XML Files to Large Text File I have a recursive function that looks through a directory (there are 6000+ files). For each XML file found - the ...
6
votes
1answer
25 views

Class that imports FX Rates from Excel File

I have a class that imports the FX Rates produced by another department. This works as intended, which is to return a Pandas DataFrame with all FX Rates by month. The DataFrame it returns is then used ...
3
votes
1answer
88 views

Use django engine to fill in a .html file on storage (no template) and use weasyPrint to convert it to PDF

I 'm new here. I wrote the following django code. I 'm opening, closing files here and saving them temporarily and deleting them. I tried to use Python's tempfile and was getting Permission Error and ...
6
votes
3answers
567 views

Die-rolling program

I'm getting into learning python so to learn I made a die-rolling application. What would you do differently? What would you suggest to improve performance/readability? What tips do you have? Suggest ...
6
votes
1answer
144 views

Python hangman code

guys I'm new to python and I decided to learn it via doing some project myself so I started working on Hangman game is there somebody willing to chceck my code for some common mistakes and what could ...
3
votes
2answers
48 views

Simple automation executing platform in Python

I'm building a platform like Rundeck/AWX but for server reliability testing. People could log into a web interface upload scripts, run them on servers and get statistics on them ( failure / success). ...
1
vote
0answers
28 views

Special Monte Carlo Simulation

I am doing a simulation of a model, RASEP. I wanted to write the optimized code to figure out Quasi-stationary state. The model is: A 1D binary string has the following dynamics $$110 \to 101$$ each ...
1
vote
3answers
82 views

Searching for many different names in a Panda frame

Consider the following example code: ...
6
votes
2answers
75 views

Pretty-print dollar amounts using custom precision for large amounts

Given a floating-point number, which is representing a dollar value, I'm aiming to return a rounded, human-readable string. Here are the rules for numbers equal to or greater than 1 million, equal to ...
0
votes
1answer
22 views

Testing Depth First Search Using Pytest

I have an implementation of depth first search, which I want to test using the pytest framework. I would be making test cases for other graph algorithms, and would ...
2
votes
1answer
27 views

Get the last activity per user per day in a dataframe

I have many users. Each time a user uses their smartphone it register them. I am determining the last time each user used their smartphone each day. Additionally smartphone usages from 18:00 to 06:00, ...
2
votes
1answer
40 views

The problem “Fun game” from a competition

I recently began to learn Python and encountered this problem. The condition: You and your friends are playing the next game. Friends write 𝑁 natural numbers in a ...
1
vote
0answers
33 views

How can the following pandas script be made more efficient?

I have an excel sheet G0.xlsx which has 3 sheets in it Winter, Summer, ...
2
votes
2answers
78 views

Python random word generator

I want to implement a random word generator that would not use Import statements. The solution is working for a *nix system. The solution does yield a random word, but please suggest: How to make the ...
2
votes
0answers
49 views

Monte Carlo Simulation of a Markov Process

A 1D binary string has the following dynamics $$1100 \to 1010,\quad 1101\to 1011$$ each with rate \$p<1\$. That is if we see \$110\$ in the string, then we change to \$101\$ with probability \$p\$....
4
votes
2answers
101 views

Program to convert number from any base to decimal

I have made a script to convert number from any base to decimal. I am trying to optimize the code because I think it is bloated and can be improved but if I change anything it affects error handling ...
2
votes
1answer
72 views

Rock Paper Scissor with a CPU (console)

I tried my hands on Rock-Paper-Scissors. But the twist is that the game has a brain that aims to learns your behaviour. The brain is a simple counter that updates the player's current choice based on ...
0
votes
1answer
48 views

Unofficial API for 1001tracklists.com

I wanted to build a scaping-API for the website 1001tracklists.com by writing classes for Tracklist and Track objects and some helpful functions: Here's the full code (GitHub): ...
3
votes
1answer
141 views

Test the hypothesis that the expected number of edges of a random connected graph is \$ O(n \log n) \$

Motivation The most common model for a random graph is the Erdős–Rényi model. However, it does not guarantee the connectedness of the graph. Instead, let's consider the following algorithm (in python-...
1
vote
0answers
37 views

Finding, substituting and executing values in dictionaries

I wrote this code for finding, substituting and executing values in dictionary, much like $() bash operator works. I used nested functions for this, forming ...
2
votes
1answer
35 views

Looking for improvements on basic dice roll code (Python 3)

I've created a code based upon a dice roll where the number of rolls is decided by user input. I am new to this, so any and all feedback will be appreciated as I feel the code is quite clunky at best. ...
2
votes
1answer
53 views

Suggestions on Python code to update/insert data in PRODUCTION system

I need suggestions on improving this code, the code is working fine ,but i'm gonna deploy this to production system, so before that would like to ask the community for any improvements/suggestions. ...
0
votes
1answer
44 views

Solving roots of negative numbers

As part of an assignment for college summer classes, I was tasked with writing a program that solves roots of negative numbers. I've ran it through the test cases I was provided and it computes ...
1
vote
1answer
59 views

Speeding up pandas apply

I would like to speed up pandas apply function. I have been using swifter . It currently takes about 5 mins for 200000 records using multiprocessing as below . Is there any way to speed this up ...
2
votes
2answers
62 views

Using deque for composing a string from 2 alternating stacks

We have 2 strings, say "JACK" and "DANIELS". We create two stacks from these strings, and then loop over them comparing first elements: whichever of the 2 goes first in lexicographic order gets popped ...
2
votes
1answer
70 views

Command line calculator utilizing OOP and RPN

I have implemented a console calculator. It has support for variables over a set of integers and the following operations: multiplication, integer division, exponentiation, addition and subtraction. ...
1
vote
1answer
45 views

Aho-Corasick algorithm to scan through a list of strings

This is a follow-up to my previous question about finding min and max values of an iterable. Aho-Corasick algorithm was suggested to solve the problem. Below is my solution with the use of ahocorapy ...
9
votes
2answers
158 views

Create football stats from a .csv file

I have collected a .csv file with some statistics about football games in the following format. Here is a sample .csv file. <...
2
votes
0answers
23 views

Noughts and Crosses Terminal Game with AI

I created a game which can play tic-tac-toe with: 0 players (AI vs AI), 1 player (human vs AI) or 2 player (human vs human). Here is the AI function which wraps around my innermost function. This ...
1
vote
0answers
45 views

Directed graph and Dijkstra algorithm using heap

I have implemented directed graph and Dijkstra algorithm using heap in Python. I first implemented an abstract base class WeightedGraph, of which ...
2
votes
1answer
53 views

Rock, Paper Scissors Game

After spending a few months learning python I decided to build a basic Rock Paper Scissors game. Basic construct of the game: Allows you to pick best of 3,5,7 Allows you to put in the name Computer ...
3
votes
0answers
59 views

Model Program For Food Orders - Too many 'break' statements

I made a program which simulates taking an order for 3 meals and a dessert. It's like those packaged food companies you see on Instagram. It asks for a name, and then goes on to ask what they want for ...
3
votes
0answers
47 views

Nvidia Energy Consumption Watcher

The idea was to write a context manager that would calculate energy consumption for the given machine learning pipeline running on a GPU. It does it by polling the current power consumption using the ...
4
votes
0answers
47 views

Snake-game using Python 3 and PyGame

I'm pretty new to Python and really new to PyGame. My snake game runs, but I guess that's not really saying much. I would appreciate feedback on the layout, techniques, or best practices of my code. <...
4
votes
0answers
22 views

Error handling best practices using a custom error handling module

I am trying to learn how to effectively use error handling in my code. To do this, I have created a class inside main.py which reads the value of a specified curve ...
1
vote
1answer
49 views

Ticket Booking Program

I am a beginner in Python, as you will see looking at my notes. This is a program that simulates seat booking in a cinema for example. The program stores the users name as a key and the seat(s) they ...
1
vote
1answer
34 views

How to make the filtering queries more efficient using flask sqlalchemy?

I have a following table in a flask app ...
1
vote
0answers
32 views

Calculation Correlation Time

I want to calculate the correlation time. First I calculate the auto-correlation function: $$ \begin{align} \chi(t) = &\frac{1}{t_{max}-t}\sum\limits_{t'=0}^{t_{max}-t}m(t')m(t'+t)\\ &-\frac{...
2
votes
1answer
63 views

Steam whitelist checker for CS 1.6

I wrote some code that reads the output of the rcon users command on the CS 1.6 console. It then notifies me of any players that are not in my whitelist.csv or are ...
1
vote
0answers
23 views

Uploading to DB from Excel with Pandas

I have this python script that uses pandas read an excel sheet then to update a sqlite db it works perfectly just wondering if I can speed it up as I am at about 70k lines ...
1
vote
0answers
27 views

Delete a linked list using recursion in Python

Given a Singly Linked-List, write a function to delete the linked list recursively. Below is my attempt. I am confused if I should use del keyword to delete the nodes or below method is better. I don'...
7
votes
1answer
220 views

Parsing a sequence of bits out of a bit field

For homework, I had to parse CPUID instruction output in C, which required a lot of specific bit-manipulation like: (eax & CACHE_LEVEL) >> 5 I ...
7
votes
2answers
276 views

Finding min and max values of an iterable on the fly

This is a follow up for my question about optimizing solution for DNA Health HackerRank problem. Short re-cap: You are given 2 arrays (genes and ...
3
votes
1answer
26 views

Pull, Tag, Save, Delete Multiple Docker Containers

First time posting and first real Python program that I use fairly frequently. I needed a way to pull a large amount of containers, re-tag them, save them (docker save) and clean up the recently ...
3
votes
3answers
124 views

Increase speed of global calculations of light under climate change using Dask

I am implementing an algorithm for estimating light at the ocean surface as a function of wind (waves, surface roughness), chlorophyll, and zenith angle. I want to do this using climate projections ...

1
2
3 4 5
83