Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [python]

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

0
votes
2answers
24 views

Words dictionary out of a text file

Please tell me what the weak spots of this code are (specially in terms of efficiency) and how I can improve it: ...
1
vote
1answer
25 views

Program to check if in line are doubled words

I made program to open a text file and count the number of lines without doubled words. This number is printed in the end. This is an example text file: ...
3
votes
1answer
16 views

Processing file inclusion directives using mutual recursion

I am preprocessing a set of files where one file is included in another file with an include tag like shown below: file A ...
0
votes
0answers
20 views

Pygame Flappy Bird Clone Black Screen

I am new to coding python, and I followed everything in a 4hr video tutorial but however, I get a black screen when I run my game. I am trying to finish this game for my long-term-project in high-...
1
vote
1answer
19 views

Converting words/numbers to Discord “letter/number emojis”

I am a beginner to Python (and programming overall) and I decided that it would be funny if I wrote a program that could convert Letters/Numbers to these "Letter Emojis" in Discord. It works but I am ...
2
votes
2answers
51 views

Simple Web Crawler for Small Sites

This script is my web crawlerfor small sites. Can you possibly review it for best coding practices? Code ...
5
votes
2answers
48 views

Simulation of spring-loaded inverted pendulum

I've finally committed to moving to Python 3 from MATLAB. I'm currently porting my MATLAB code, and I'm sure I'm missing a lot of common best-practices. For reference, I'm simulating a spring-loaded ...
0
votes
1answer
21 views

Time limit exceeded in K-th symbol in Grammar (LeetCode)

I am taking efforts to solve problem K-th Symbol in Grammar - LeetCode K-th Symbol in Grammar On the first row, we write a 0. Now in every subsequent ...
3
votes
2answers
41 views

Python, Rock, Paper, Scissor

Recently i wanted to test my Python knowledge so I'm taking some challenges. I came across a Rock Paper Scissor challenge and I wanted to make it with less code and reuse the same code over and over. ...
2
votes
2answers
41 views

Python - Random Mandala

I did a project in Python where I combined user-input, random, and the turtle module to make a sort of "Mandala Generator", or a program that can generate a simple design either randomly or by the ...
-1
votes
0answers
18 views

When to couple output from one class as the input to another class? [on hold]

I am trying to better plan the class structures of a large code base in python. The project is a data science project involving data cleaning, data analysis, etc. I model all the data cleaning tasks ...
0
votes
1answer
39 views

Fill /dev/random via Bitcoin exchange value

I have written the following random numbers generator. I would like to know how safe this is and if it is suitable for use in computer engineering. For me, the result looks very random, but would like ...
0
votes
1answer
64 views

Forming the best possible poker hand [on hold]

This is what the function is doing: it gets two arrays of tuples with 5 items each - hand = [H1,H2,H3,H4,H5] and board = [B1,B2,B3,B4,B5] What I need to do is check all arrays formed by 2 items from ...
2
votes
1answer
29 views

Simple command-line roulette game

I developed a simple command-line roulette game. Your only options are betting on color, but you can bet multiple times in one round ...
4
votes
0answers
37 views

Golf Physics “Game”

Continuation of this post I wrote a program in pygame that basically acts as a physics engine for a ball. You can hit the ball around and your strokes are counted, as well as an extra stroke for ...
-1
votes
0answers
44 views

Correct Python script structure [on hold]

I've been programming in Python for some time now and I've always used the below structure to organize my code. Lately, I've been wondering if this structure is an ideal and correct one to use ...
0
votes
1answer
27 views

Python code for handling HTTP cookies

We would like for a code review for our Python code. The code is written in Python 3.7 and is part of a class handling HTTP cookies. The code: ...
1
vote
1answer
38 views

Efficient way to add a colon before and after every word in strings inside a Series

I was working with twitter data, and extracted every emoji from the data. But, when I passed that data through CountVectorizer, colons where substracted from the ...
2
votes
1answer
44 views

Aggregate Pandas Columns on Geospacial Distance

I have a dataframe that has 3 columns, Latitude, Longitude and Median_Income. I need to get the average median income for all points within x km of the original point into a 4th column. I need to do ...
7
votes
2answers
75 views

Maze generator for teaching Python 3

I am teaching programming (in this case - 1 on 1 tutoring of a teenager interested in programming) and this code will be a final stage of a progression toward program generating a maze. Any comments ...
0
votes
0answers
31 views

Python: Max function on dictionaries [on hold]

This time, write a procedure, called biggest, which returns the key corresponding to the entry with the largest number of values associated with it. If there is more than one such entry, return any ...
6
votes
3answers
2k views

Extract all GPU name, model and GPU ram

I currently use this code to extract the required GPU data. Can you review this method for efficiency or best coding practices? Code ...
-1
votes
3answers
66 views

How to flatten a list of lists? [on hold]

How to flatten a list of lists in more pythonic way? This is the code I tried. ...
1
vote
1answer
73 views

2-Player Tank Battle Game

I've created a 2-player tank battle game. The code however seems like it could be greatly simplified and there are a few issues. One of which is the hitboxes of the tank seem a bit unreliable. ...
-3
votes
0answers
22 views

Python- HTML comparing two HTML files and ignoring elements [on hold]

I am using python to compare two HTML files and it spits out the difference, but i need it to ignore certain elements like ""... the value part as it will always change and be different. Please could ...
7
votes
1answer
44 views

ArXiV Technical Paper API Github Repo

My name is Ethan and I am trying to build an API for scaping technical papers to use for developers. Right now it only works for ArXiV but I would greatly appreciate some mentoring or a code review of ...
3
votes
3answers
98 views

Computing average duration per user from a large CSV file that doesn't fit in memory

We have a large log file which stores user interactions with an application. The entries in the log file follow the following schema: {userId, timestamp, actionType} where actionType is one of two ...
3
votes
1answer
34 views

Getting limited user input: strings and numbers

I posted part of this module earlier (here). I implemented that feedback and now am looking for another round of gut checking. Questions/Concerns I have: Does the way I've structured my functions ...
5
votes
1answer
58 views

Extracting watermark from a video using Python

I'm extracting a few frames from a video: Comparing the similarity or equality of pixel color (from first two images) Saving to a new image Comparing the new image (conjunction of first two images) ...
5
votes
3answers
117 views

Python coin flipper

I know this is the simplest code that you have probably ever seen but its the first thing I've ever made. Any ideas on how to improve it or add new functions to it? ...
1
vote
1answer
137 views

Solution to Codejam 2019's Pylons

I'm trying to solve Pylons from the 2019's round 1A. The analysis suggests that a brute force approach should work. However, my Python 3 solution doesn't pass the 2nd test case. Can I make it faster ...
4
votes
0answers
48 views

Data Model Design and Inheritance in Python

I am implementing a data model in python and would appreciate any feedback. Model My data structure can be reduced to the following: ...
1
vote
0answers
36 views

Python - Speed up nested for loops in numerical experiments

I am trying to run some numerical experiments, and wondered if there was any way to run my code faster. The function runs over combinations of several parameters so in my mind I thought the best thing ...
-2
votes
0answers
13 views

Understanding a DDP client using WebSockets and EventEmitter [closed]

I came accross a code about a DDP client I am trying to understand. The code contains two main classes: DDPSocket which inherits from WebSocketClient and from EventEmitter. The second class inherits ...
2
votes
1answer
50 views

Simple dungeon game [on hold]

Curious on how I can consolidate or generally streamline my code here: ...
4
votes
0answers
42 views

Basic Python HTTP Server

It's an extremely simply HTTP server in Python using the socket library, and a few others to get the MIME type, etc... I've also avoided the ../../ vulnerability, ...
25
votes
5answers
3k views

Fishing simulator

I'm new to Python, for a school project I created a "fishing simulator". Basically, it is a use of random. I know that my code is repetitive towards the end, but I don't know how to simplify it. <...
2
votes
1answer
51 views

Analyzing patient treatment data using Pandas

I work in the population health industry and get contracts from commercial companies to conduct research on their products. This is the general code to identify target patient groups from a provincial ...
4
votes
1answer
28 views

Count words in a list of titles, with some cleanup

I have a list of article titles, where I wish to count the number of occurrences for each word (and remove some words and characters). The input is in a .csv file where the titles are in column '...
1
vote
0answers
18 views

Requests / Facebook API - Dealing with Errors

I work in marketing and I am currently trying to aggregate data for 50 facebook pages on the same Business Page. I have a loop ...
2
votes
1answer
132 views

Faster way to 3 nested for loop python

I am calculating parameters for a time series and the data size is very big. How can I make my function faster? The following function, param, calculates parameters ...
2
votes
1answer
22 views

Leftmost bisect search to find valid perfect square

I am working on Valid Perfect Square - LeetCode and wrote a standard leftmost bisect search to solve the problem: ...
3
votes
1answer
69 views

First Python program: Tic-Tac-Toe (Followup)

I am unsure if I followed the the suggestions on my previous post. I have only been working on programming for about 3 weeks so any more suggestions or insight would be more than welcomed. ...
4
votes
0answers
28 views

Decorate a python function to work as a Google Cloud Function

I wrote this for a class project, the backend for this dog voting website. I noticed duplicate code among multiple functions I was writing to be deployed as a cloud function: they all were wrapped in ...
3
votes
1answer
28 views

Python: Combining Two Rows with Pandas read_excel

I am reading an Excel file using Pandas and I feel like there has to be a better way to handle the way I create column names. This is something like the Excel file I'm reading: ...
3
votes
1answer
55 views

Google Kick Start Practice Round 2019 - Mural

My code exceeds the time limit on the second test set. A suggestion/hint of a better algorithm would be appreciated. Problem Thanh wants to paint a wonderful mural on a wall that is N ...
2
votes
2answers
47 views

Fastest way to find dataframe indexes of column elements that exist as lists

I asked this question here: https://stackoverflow.com/q/55640147/5202255 and was told to post on this forum. I would like to know whether my solution can be improved or if there is another approach to ...
4
votes
0answers
30 views

Convert Amazon transaction data for import into accounting system

At the end of each billing cycle, Amazon generates a raw transaction file for my store's orders that cycle. I am converting that raw transaction file into a .csv file to be imported into my accounting ...
4
votes
1answer
45 views

Django model for real estate

I have built a real estate management system with Django. I want to know if my design database was wrong. Please let me know how to improve it. Should I make the models use more than two tables (...