Stack Exchange Network

Stack Exchange network consists of 174 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

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.

3
votes
1answer
7 views

Forcing the user to choose from a set of options (in Python)

First Code Review request =) I wrote this after making several projects that required a user to pick an option. I wanted to have a set way of forcing that choice in all of my projects. The module also ...
1
vote
0answers
5 views

Hamming Distance in Python

I was solving this Leetcode challenge about Hamming Distance. Would love feedback on my syntax and code style. Here's the challenge description: The Hamming distance between two integers is the ...
1
vote
0answers
17 views

Codewars: N smallest elements in original order

I am consistently timing out on the mentioned kata: Task You will be given an array of random integers and a number n. You have to extract n smallest integers out of it preserving the original ...
-1
votes
0answers
22 views

Enigma machine implementation (Python 3) [on hold]

So guys, maybe this kind of question has been asked many times before, but I finally tried to implement this Enigma machine. I have done it half the way: The algorithm is revertible. However, it ...
2
votes
0answers
17 views

setting up mock and fixtures for for multiple pytest unit tests

I've been implementing a MySQL client with the later purpose of automating monthly reports. At the moment, I've got two distinct use cases: Executing a query and printing the results in files. The ...
2
votes
1answer
50 views

Finding recessions in US GDP data using pandas

For an assignment, I am identifying the first quarter of the 2008 recession in the United States. The Excel data I'm using can be downloaded here: gdplev.xls. How can I improve this pandas code to ...
2
votes
1answer
23 views

GIF/PPM to greyscale converter

This is my take on an image → greyscale converter. ...
3
votes
0answers
32 views

Socket chat room in Python

This is a Python chat room that I've been working on and it enables to you to chat to other people on the same network through Python. Server.py: ...
1
vote
0answers
23 views

Python script to add unittest decorators to source code files

This is a simple Python script to add @unittest.skipUnless() decorators in a specified format above every function starting with ...
3
votes
0answers
39 views

Metaclass to run a __first__ method for the first instantiation of a class

I had an idea for a __first__ special method for a class. It would be run after __new__ and before ...
-2
votes
0answers
35 views

Is there a way to compress this? [on hold]

This code seems very large and clunky, but I don't know any way of compressing it and making it smaller. Does anyone have any solutions? ...
1
vote
0answers
45 views

Optimize Application of Python Gensim Search Functions

I have a DataFrame that has a text column. I am splitting the DataFrame into two parts based on the value in another column. One of those parts is indexed into a gensim similarity model. The other ...
-2
votes
0answers
22 views

Generalized Hailstone that converges with the sequences [on hold]

Can someone please help me solve this problem in python? Thank you in advance! ...
3
votes
0answers
24 views

Export EXIF data from thousands of images to CSV

I have written a script that retrieves specific fields of Exif data from thousands of images in a directory (including subdirectories) and saves the info to a csv file: ...
2
votes
1answer
24 views

RESTful API echo server using Python bottles

I just wrote an echo server that responds to curl requests with the method used and the data sent. Sticking to GET and POST for now, but I would like to know if there's something I can do to improve ...
1
vote
1answer
35 views

Leetcode 3Sum problem using hashmap in Python

For practice, I solved Leetcode 15. 3Sum question: Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives ...
0
votes
0answers
10 views

how to get char ascii value in python without using builtin functions [on hold]

how to get char ASCII value in ' python without using built-in functions ord("char") byearray("some char") byearray("some char")
-1
votes
0answers
15 views

When scraping webpage XPATH variable returns Unfinished Literal [on hold]

I am trying to scrape Amazon for ASIN Best Seller Rank and when I run the script in python it returns an unfinished literal error Everything works except for the Best Sellers Rank. I would really ...
6
votes
2answers
377 views

Python Making Brute Froce Crack Faster

I made an Brute Force Cracker with python, but its extremely slow. How can i make it faster? ...
4
votes
0answers
25 views

dynwg: A DynDNS watchdog for WireGuard via systemd-networkd

Preface I'm using WireGuard as a VPN solution to connect a remote client permanently to my home server. Unfortunately due to Consumer DSL-related IP address changes, the client loses the connection ...
2
votes
2answers
65 views

Return array with products of old array except i

Coding problem: Given an array of integers, return a new array such that each element at index i of the new array is the product of all the numbers in the original array except the one at i. My ...
5
votes
2answers
230 views

Get all monotonic sublists from a list

So, i recently wrote code that can count the number of monotonic items (increasing, decreasing and constant). For an input such as x = [1,2,3,3,2,0] The provided ...
-3
votes
1answer
30 views

Should I drop the 'else' from an 'if elif else' or 'if else' segment? [closed]

I often write statements such as: def foo(): if condition: return True else: return False To me, it makes sense to just drop the else, giving ...
4
votes
1answer
48 views

NFL data scraper

I made a Python 3 class that scrapes data from Pro Football Reference. It uses requests and beautifulsoup4 to gather the data ...
0
votes
0answers
14 views

Concatenating linked named entity tags in a list of tuples [closed]

Given a list of tuples, I want to merge all L- tuples with their corresponding B- tuple. The List is constructed in order, so that all L- tuples must follow a B- tuple This works, but I'm fairly new ...
-2
votes
0answers
30 views

The following code is in Python. I am a beginner. What is wrong with my code? [closed]

The following code is in Python. I am a beginner. What is wrong with my code ? Code to find median of 2 sorted lists. class Solution: def findMedian(self, A, B): med1 = med2 = i = j ...
2
votes
2answers
69 views

Is the sum of 2 numbers in list k

I got a coding problem to solve and was wondering if I got a commonly acceptable and efficient/clean solution. If there is a better way I'd gladly hear it. given a list with numbers return if the ...
4
votes
0answers
33 views

Wrapping argparse to use configuration file

I want to be able to both provide options through command line and from a configuration file. A single option could be served either by the user or by the configuration. But if is provided by both, ...
2
votes
1answer
36 views

Unit test for a function that transforms a PANDAS dataframe

I am currently working on a project that uses many dataframe wrangling. The intention is to write test to check that the output functions are correct. I have written a test for a dataframe function ...
8
votes
4answers
1k views

Counting lowercase and uppercase letters in a string in Python

I am writing a program to count the number of uppercase and lowercase letters in a string. I came up with something that works, but as I am still a beginner I have a feeling writing the code this way ...
-1
votes
2answers
74 views

Arbitrary probability dice

I have to make this: Each set consists of a number of equal objects that generate numbers from a finite set with an arbitrary probability distribution. I did make it, but it feels so long. How can I ...
4
votes
3answers
271 views

Collect subsequences of consecutive integers

I've written a function to split a list into several lists with consecutive integers, e.g.: extract_subsequences([1,2,3,7,8,9]) ...
3
votes
1answer
77 views

Word break problem with recursion and memorization [closed]

For practice, I solved Leetcode 139. worbreak question: Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-...
3
votes
1answer
46 views
1
vote
1answer
54 views

Check if given integer is a palindrome

This code checks if the given integer is a palindrome. If it is, prints given integer is a palindrome else, not a palindrome: ...
0
votes
1answer
34 views

Binary search a sorted list of integers in Python 3

y is the value I am searching for. Is this the correct implementation for binary search? ...
0
votes
0answers
29 views

Tic Tac Toe game in Python 3.X using tkinter GUI version 2

I am completely new to programming and to python and as my first self-learning project I am creating a simple Tic-Tac-Toe game. I have already posted a version of my code here on stack: Tic Tac Toe ...
2
votes
2answers
53 views

Python web page to display SSL certificate status

My task was to create a Python script and connect to various TLS sites and grab the expiry dates. I've done this with openssl and ssl modules just fine. In my mind I was wanting to create a web page ...
0
votes
1answer
36 views

Generate a text file representing an email for a job application followup

Purpose: After you've submitted a resume and cover letter for a job position, you haven't heard anything back, so you decided to send a follow up email. The script generates the follow up e-mail based ...
9
votes
2answers
417 views

Sierpiński's carpet fractal animation 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 nice image of ...
1
vote
1answer
27 views

Pandas: updating cells with new value plus old value

I have a folder with zip files that contain CSVs for each day. Each CSV contains rows with IPs and a company ID. I want to calculate a distribution of the number of firms accessed. Meaning that I want ...
3
votes
1answer
33 views

Cashbox count program

I wrote this as an aid to count money that is in a cash box. are there any flaws in the code or any improvements I can make. ...
9
votes
4answers
1k views

Compute binary XOR of all integers in a range, mod 2

here I am taking 3 inputs. 1st input will take test cases and the other two input will take starting and ending range. the program is running fine as expected but the limit of this question for ...
2
votes
1answer
70 views

Leetcode Three Sum in Python

Here's my solution for the Leet Code's Three Sum problem -- would love feedback on (1) code efficiency and (2) style/formatting. This is Python 3. Problem: Given an array nums of n integers, are ...
5
votes
1answer
38 views

Find minimum and maximum numbers

Write the find_boundaries function, which will take a list of numbers. The function should return the tuple with the smallest and largest number in the set. If ...
4
votes
2answers
79 views

Shopping List program made in Python 3

This is a shopping list program made in Python 3 and it will send the list by email. I am not very experienced but I consider this program as a starting point to what I will do next. ...
1
vote
1answer
39 views

BTC price checker with web scraping, regex and Tkinter GUI

The purpose of this was to practice web scraping, regex and GUI. I use a popular bitcoin website to scrape the names and prices of the top 16 cryptocurrencies. I then create a data frame and make a ...
4
votes
1answer
48 views

Uploading songs from website to database and then to Spotify

My Python program parses songs from a website, corrects song titles and artists with the Last.fm API, searches for the spotify uri using the Spotify API, stores all the information in a SQLite ...
1
vote
0answers
20 views

API Client: Querying data out of an endpoint

I have a simple piece of code which connects to an API, does a request and gets back the raw data. After getting this data I create several objects (models) and persist them into a MongoDB database. ...
4
votes
1answer
37 views

Blackjack Game in Python 3/curses

You were all so helpful with my Tc Tac Toe games in C. I was encouraged to put it up on GitHub and two very helpful users refactored it in ways that really taught me a thing or two. While I have ...