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
0
votes
1answer
37 views

Python: Bubble Sort

After implementing suggestions from an earlier, related question (Python: Selection sort), I have written this code. Could you help me to improve this code? ...
2
votes
0answers
74 views

Google drive backup robot

I have a lot of files. I care about those files. I also care about good programming practices and learning proper python. Given the described context, it seemed appropriate to implement my own ...
5
votes
2answers
51 views

File duplicate finder

In an attempt to clean out my picture collection I made a script to find all duplicate files ...
2
votes
2answers
73 views

Compare elements of each list of lists to corresponding ones in different list

My goal is to reduce processing time significantly (if possible) by making this working code more efficient. Currently 50k row by 105 column data taking about overall 2 hours to process. Share of this ...
4
votes
0answers
24 views

Python automatic import and install script

In the following script, I am trying to infer if the modules are managed by a conda environment or not and based on that, I am trying to auto install and import the modules. [I skipped around 5 to 6 ...
2
votes
1answer
62 views

Parsing data from JSON API in Pandas

I made a little program to parse data from an API. I do not have experience with Pandas. It is working but I would like to know how to do that better and more efficiently. ...
8
votes
2answers
278 views

Sentence editor

I wrote a simple sentence editor which capitalises first word, deletes redundant spaces and adds a dot in the end unless another sign of punctuation is already present. Please help me to improve my ...
1
vote
1answer
61 views

Python: Selection sort

After implementing suggestions from an earlier, related question (Python: Insertion Sort), I have written this code. Could you help me to improve this code? ...
1
vote
2answers
36 views

Parse date format in Pandas using Python

I have a column in a Pandas Dataframe containing birth dates in object/string format: 0 16MAR39 1 21JAN56 2 18NOV51 3 05MAR64 4 05JUN48 I want to ...
3
votes
1answer
38 views

Evaluate an expression binary tree - Daily Coding Challenge

Here is my solution for the Daily Coding Challenge 50 Given an arithmetic expression in the form of a binary tree, write a function to evaluate it Example ...
5
votes
1answer
95 views

Coalescing ranges that have the same label

I am working with some data that requires keeping track of different types of ranges. There are three key attributes to keep track of: type (str): the "type" of the range start (int): the value at ...
4
votes
1answer
85 views

Agent based model in Python

My model is based on the Ultimatum Game. I won't go into the intuition behind it but generally speaking it functions as follows: The game consists of a n × n lattice on which an agent is placed at ...
4
votes
1answer
44 views

URL builder in Python

I created a code that will create, or rather build a URL based on the configuration. Everything works, however with the expansion of my project I added multiple languages etc. every section only ...
0
votes
1answer
27 views

tablename alias in attribute name

I have dataframe like this: ...
4
votes
3answers
95 views

Papers, Please - Kata from CodeWars - Python

This is possibly one of the longest katas I've finished so far. https://www.codewars.com/kata/59d582cafbdd0b7ef90000a0/train/python I've been working on this one for about an hour a day for about 2 ...
1
vote
1answer
44 views

Efficient way to get value from a dataframe and append new dataframe

I have a dataframe that have about 200 million rows. the example of dataframe is like this: ...
2
votes
2answers
51 views

Knight's Tour - Python

Below is my recursive solution for the Knights Tour. The user can set the board size and the program will print the first legal knight's tour it finds. As there are potentially millions of correct ...
0
votes
0answers
32 views

Clustering using k-medoids

This is the program function code for clustering using k-medoids ...
2
votes
1answer
41 views

Culling strings from a list that are substrings of other list elements

I'm bothered by my answer to this SO question. I'm pretty sure it's more efficient than the sort-and-cull implementations, but I'm having trouble expressing that in a way that I trust. Also, it's ...
9
votes
4answers
1k views

Skipping over failed imports until they are needed (if ever)

We have a program with many dependencies. Because the user may not want to use all of them, the program should skip over failed imports and only raise an error if absolutely necessary. e.g. if the ...
2
votes
2answers
56 views

SQL log file parser

I have a read log file function to get select operation from database log file like this: ...
2
votes
0answers
29 views

Small socket based packet Library

I'm currently writing a python script which needs some simple networking. After some playing around with sockets, this emerged, but as this is my first foray into sockets I'd really like a second ...
5
votes
1answer
96 views

Building a frequency dictionary from a Pandas dataframe

I need to make a frequency dictionary from a pandas series (from the 'amino_acid' column in dataframe below) that also adds an adjacent row for each entry in the dictionary (from 'templates' column). ...
2
votes
1answer
36 views

Length of the longest common sub sequence bottom up

Could I get some feedback on this code? I included a test case as well. This code computes the longest common sub sequence given paired data, it was not part of any challenge I just did it to learn ...
0
votes
1answer
30 views

The 100 chair survivor challenge

I came across the following challenge. Here is my implementation in Python 3.7 A room has 100 chairs numbered from 1-100. On the first round of the game the FIRST individual is eliminated. On the ...
1
vote
2answers
53 views

Maximum contiguous sum in an array

The following code is my solution for the following Daily Coding Challenge Given an array of numbers, find the maximum sum of any contiguous subarray of the array. For example, given the ...
3
votes
2answers
217 views

Pull-up sequence accumulator counter

I wanted to create a function describing a sport game called "Leader". The idea is that you make as many push-ups as you can, increasing each repetition by 1 and as you reach your maximum, each next ...
2
votes
0answers
18 views

Create mosaic task #2

This post is a continuation of post here: Create mosaic task. I improved code readability, hopefully it'll be reviewable now. Once again, I'm asking for tips to write better code. Task: The point ...
4
votes
1answer
136 views

Policemen catch thieves

Given an array of size n that has the following specifications: Each element in the array contains either a policeman or a thief. Each policeman can catch only one thief. A policeman ...
2
votes
1answer
35 views

Efficient resampling of time series

I'm trying to create an efficient function for re-sampling time-series data. Assumption: Both sets of time-series data have the same start and end time. (I do this in a separate step.) Resample ...
2
votes
1answer
43 views

Python IMAP login bruteforcer

Below is the code of a command line tool built with Python that will download email via IMAP. Omitted from the code below are 2 important functions parse_line and <...
1
vote
2answers
101 views

Egyptian fractions in Python

Here's my code for the Egyptian fraction written in Python. I need your feedback if there is any room for improvement. ...
3
votes
1answer
198 views

Sticking to a working proxy generated by a rotating proxy script

I've created a script in python to make proxied requests by picking working proxies from a list of proxies scraped from a free proxy site. The bot traverses few links to parse the urls of the ...
3
votes
1answer
60 views

Python - Activity Selection - Greedy Algorithm

I've done this activity selection piece of code, which is a greedy approach. I need some feedback/suggestions. ...
-4
votes
1answer
47 views

What is wrong with my 'except' code here? [closed]

I am learning python and am working through some try and except codes. What is wrong here? The code aims to convert the input ...
2
votes
2answers
98 views

Beginner text adventure game

I am new to Python and I have not yet done any OOP. I wrote this text adventure as a first project and I would like to know if there is a better and more efficient way to write my code within its ...
3
votes
1answer
70 views

Boggle solver - Updated (with Trie)

Here is an update to my previous boggle solver. The new version has an almost instantaneous output, removing the need to limit the length of words being searched for. Any comments on my general ...
2
votes
0answers
34 views

Client wrapper for sending data to a downstream process

I am building a Python client for an alert process engine. The users can use this client to publish and clear the alerts. The client exposes two methods publish and clear to the users. These methods ...
2
votes
0answers
66 views

Pricing data checker script

I was recently given a task to implement a data-checker script which given an input file containing (date, last_price) values should check for 3 different kind of errors - missing values, stale values ...
5
votes
1answer
94 views

A recursive Boggle solver

`Boggle is a word game in which letters are randomly placed in a 4x4 grid e.g: A D Q P N L E M O S R T V K J H Words can be started from any letter and are ...
2
votes
0answers
48 views

Python adding partialmethods to a class at compile time

I am writing a class for delayed operations on variables which are resolved at a later time. I am using pythons operator overloading but my class definition seems very boilerplatey. Is there a more ...
11
votes
3answers
2k views

Prime sieve in Python

I was trying to write Sieve for the first time and I came up with this code: ...
3
votes
1answer
69 views

Deduping files using hardlinks

I'm trying to organize my gallery, and I have certain folders rife with copies. My daily work is mostly javascript and php, being your generic web developer. However I took this as an opportunity to ...
3
votes
1answer
47 views

Apply same format function to each python print() parameter

I have a python print statement and inside the string I wish to print are four digits. I would like to apply the same formatting function to each param. I am not ...
6
votes
1answer
105 views

Python3 OOP Tic-Tac-Toe

I'm studying Object-oriented Programming and decided to apply some things doing an Object-oriented Tic-Tac-Toe. I wanted to know if you have some hints of what to improve and why! ...
10
votes
3answers
1k views

Find the common ancestor between two nodes of a tree

Here is my code in Python for to find a common ancestor between two nodes in a particular tree. This is a question from Cracking the Coding Interview that I decided to implement on my own. No one has ...
2
votes
2answers
372 views

Regex version of strip() - Ch. 7 Automate the Boring Stuff

Here is a practice exercise — Regex version of strip() \$-\$ Write a function that takes a string and does the same thing as the ...
5
votes
2answers
378 views

Fantasy game inventory — Ch. 5 Automate the Boring Stuff

Here is a practice exercise — Fantasy Game Inventory \$-\$ You are creating a fantasy video game. The data structure to model the player’s inventory will be a dictionary where the keys are string ...
0
votes
2answers
71 views

(Leetcode) Valid parentheses

This is a Leetcode problem - Given a string containing just the characters '(', ')', '{', ...
5
votes
2answers
98 views

Character Picture Grid exercise - automatetheboringstuff

Regarding the Character picture exercise located at the end the following page: https://automatetheboringstuff.com/chapter4/ Say you have a list of lists where each value in the inner lists is a ...