Questions tagged [python]

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability. Use the python tag for all Python related questions. If you believe your question may be even more specific, you can include a version specific tag such as python-3.x.

Filter by
Sorted by
Tagged with
-1
votes
2answers
71 views

Improving read/write loops in Python [closed]

Task: I'm importing a .CSV files as a pandas dataframes. I'm writing one column of that dataframe to a .txt file. Importantly, each row of the column must only be written as one row in the text file, ...
-1
votes
1answer
244 views

Tic-Tac-Toe in python 3.5.2 [closed]

I am trying to make a fun, easy game of tic-tac-toe, but my code editor is very limiting. If anyone has a suggestion to make this better, or a good, free code editor, I would love to know. By running ...
-1
votes
1answer
53 views

Using dictionary.get() in if condition [closed]

I'm currently building up an object from dictionaries with lots of optional key/value pairs. To handle the different cases i check if i need to add anything like: ...
-1
votes
1answer
36 views
-1
votes
1answer
75 views

Unit-test for a program that relies on module-level data [closed]

Background: The following code is unit-testing for another program called pw in the code. The "module-level data" is represented in the @classmethods. The setUp ...
-1
votes
1answer
66 views

Python Prime_Numbers Algorihtms TypeError() [closed]

TypeError: range() integer end argument expected, got float. If I use Integer It will not include 3 as Prime Number...I do not want to add 3 same like 1... Code--> ...
-1
votes
1answer
257 views

Bruteforce Keys from GET Input with mechanize

My Script tries to find a password, using a brute force approach. The password is then tried using a GET call to a website. I'm not happy with the way the script looks, particularly the number of ...
-1
votes
1answer
708 views

Selenium Kijiji web scraper

I have this script working pretty well but I know that there must be many things that I could do better to make it more efficient. ...
-1
votes
1answer
1k views

Triple for loop for a data set

I am writing a triple for loop in Python. Since the data set is larger, it takes more than 1.5 hours to finish. Is there any fast way to avoid the loop? ...
-1
votes
1answer
410 views

The mood of the nation - Twitter trend

This assignment is taken from Berkeley's CS61A page here. Introduction In this project, you will develop a geographic visualization of twitter data across the USA. You will need to use ...
-1
votes
1answer
316 views

LPTHW Ex51 with image upload [closed]

Here's what I ended up with for Learning Python the Hard Way Ex 51 with image upload (save and display). The form: ...
-1
votes
3answers
234 views

Better sorting speed

import sys x=int(sys.stdin.readline()) lst = [int(sys.stdin.readline()) for i in xrange(x)] lst.sort() print lst How can I make this code faster for large ...
-1
votes
1answer
933 views

Use of multiple value errors in Python [closed]

Review this code. ...
-1
votes
1answer
102 views

Find all subsets of a vector that sum up to another vector

I'm looking for a way to make my code more simple. This code takes a list of vectors and returns all subset of that list that sum up to another vector. For example: ...
-1
votes
2answers
122 views

Unpacking sequences for functions [closed]

After watching Raymond Hettinger, I decided to go through my code and make it faster and more beautiful. The example given on the slides is, unfortunately, not good enough to get me going (ref. https:/...
-1
votes
1answer
87 views

Scraping odds portal with beautiful soup

This code scrapes www.oddsportal.com for all the URLs provided in the code and appends it to a dataframe. I am not very well versed with iterative logic hence I am finding it difficult to improvise on ...
-1
votes
1answer
98 views

Finding longest word in a sentence

A problem from Coderbyte. Find the longest word in a sentence after removing the punctuations and if two or more words are of same length return the first word Below is my solution: ...
-1
votes
1answer
61 views

django multiple if else refactor

I have a function with multiple if else statements that I'm trying to simplify in Django Is there a pattern or maybe a better modeling approach that I could use here? The idea behind is to have a ...
-1
votes
1answer
2k views

Foo Bar - Power Hungry challenge test case failing on unknown edge cases [closed]

The challenge is to find the maximum product of a subset of a given array. Here's the problem: Write a function solution(xs) that takes a list of integers representing the power output levels of ...
-1
votes
1answer
44 views

Trying to get every 6th set of 4 bytes from a python array [closed]

I have an array of bytes 6144 bytes long. I want to extract a set of 4 bytes every 6th set of 4 bytes . So every 24 bytes I want to extract 4 of those bytes and join them in a new array. So ...
-1
votes
1answer
59 views

Accessing function of class A from RESTful API that runs in class B [closed]

I have the following code ...
-1
votes
1answer
40 views

comparing between binary search method and linear search [closed]

I am a python beginner and I wrote a program that compares between the binary search method for finding a number and the linear one. However, when I run it It does not function properly and would ...
-1
votes
1answer
180 views

Decoding a string encoded by Caesar Cipher and some delimiters [closed]

I have the following code which I seek to optimize. The result of the bruteforce I already have but I'm just trying to learn some more python using the same example. The code in the data needs to be ...
-1
votes
1answer
772 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 ...
-2
votes
3answers
298 views

Heap sort implementation in Python 3

This code relies on Python3.7.4 I'm learning Heapsort in python 3. Please show me the errors in my code. Runs on my computer but tell me if Python rules or not. ...
-2
votes
2answers
1k views

Pascal's triangle with memoization

Problem: Pascal’s triangle is a useful recursive definition that tells us the coefficients in the expansion of the polynomial (x + a)^n. Each element in the triangle has a coordinate, given by ...
-2
votes
3answers
166 views

Simple Python script seems to stop when N >> 1

Edit : So I let the code run for 70 hours and it did not return. Thus I stick to my point, it does get stuck on something, fails silently and let the bash hanging. From the time increase compared to ...
-2
votes
2answers
88 views

How to flatten a list of lists? [closed]

How to flatten a list of lists in more pythonic way? This is the code I tried. ...
-2
votes
2answers
475 views

Assigning movements to counters for a board game, using die rolls. [closed]

I have finished writing a program, and was wondering if I could make it any more efficient or generally more sophisticated that the current version. The below section of code is where I think ...
-2
votes
2answers
72 views

Python sub-process scripts

...
-2
votes
1answer
169 views

On Finding Coin Jams

The problem can be found here and is essentially asking us to generate J many numbers containing N many digits, where these digits have to be either 0 or 1. The catch is that the these numbers that we ...
-2
votes
2answers
7k views

Brute force script for printing a password

I wrote a script that reads a file containing a password ("password"), loops each character in that file to see if it matches a character in the alphabet, and when every letter has been found the ...
-2
votes
1answer
57 views

Formatting a long filesystem path in Python [closed]

This is a follow up to Log probe requests of WiFi devices focussing on a specific element of the code. I have this line of code: ...
-2
votes
1answer
389 views

Simple Python tic tac toe [closed]

I'm a beginner in python so I decided to take a simple challenge and wrote tictactoe How to write it better in future? What's wrong with my code? ...
-2
votes
2answers
163 views

Faster mapping/modifying values in a large list of Python dicts? [closed]

I have some code that I'm trying to speed up. Maybe what I've got is right, but whenever I ask on StackOverflow somebody usually knows a clever little trick "Use map!", "try this lambda", or "import ...
-2
votes
1answer
117 views

How to make this code more compact and readable

My below code is working fine but I want to make it more Pythonic. Furthermore, I want to get rid of nested ifs and make the code more compact and readable. Any suggestions? Here project_id and ...
-2
votes
1answer
46 views

what is the best practice concerning opening CSV files in python [closed]

I am looking for the best way to save regular data from a series of sensors to a CSV file. the program will be reading every sensor once a minute 24/7 and needs to report the results to a CSV file ...
-2
votes
1answer
940 views

“Finding possible candy permutations” HackerEarth challenge

Problem Statement Shil, Aditya and Utkarsh go to a candy shop. There are N candies present in the shop, which are indexed from 1 to N. All three of them select one candy to eat. However, ...
-2
votes
2answers
645 views

Varying the parent class dynamically in Python [closed]

I am trying to dynamically pick a parent class in Python 2.7: ...
-2
votes
2answers
78 views

Time diff in days [closed]

I have the following snippet: ...
-2
votes
1answer
90 views

Python linter vs PEP8 [closed]

I am working on a Nagios Scraper in Python3. I have Github set to automatically run checks (i.e. Python Linter) to make sure the code is good. It is currently failing that check, although the code ...
-2
votes
1answer
76 views

Eliminate shorter substrings from larger one

I have a dictionary that stores a string and its frequency which looks like this ...
-2
votes
1answer
200 views

What is better: join(dirname(__file__), '../../../testdata')) or join(dirname(__file__), '..', '..', '..', 'testdata'))

Both ways work: os.path.join(os.path.dirname(__file__), '../../../testdata')) or ...
-2
votes
1answer
7k views

hailstone sequence using recursion in python [closed]

Douglas Hofstadter's Pulitzer-prize-winning book, Gödel, Escher, Bach, poses the following mathematical puzzle: Pick a positive integer n as the start. If n is even, divide it by 2. If n is ...
-2
votes
1answer
104 views

Adding 1 million combinations of numbers to a file

The code adds approximately 1,720,000 different combinations of numbers to a file, some_other_file.txt. The numbers range from 2 digits long to 16 digits long. I ...
-2
votes
1answer
61 views

Using Python's getter/setter [closed]

I have written below code to create/get a dict with n number of key, value pairs. Main idea is to use the same instantiated class object across my code and play around with k/v pairs. Current ...
-2
votes
1answer
134 views
-2
votes
1answer
774 views

Project Euler # 50 Consecutive prime sum in Python

The prime 41, can be written as the sum of six consecutive primes: 41 = 2 + 3 + 5 + 7 + 11 + 13 This is the longest sum of consecutive primes that adds to a prime below one-hundred. The longest sum ...
-2
votes
1answer
81 views

A function that uses requests in order get JSON content

Any typing, or other improvements that you could make for this simple function? ...
-2
votes
1answer
625 views

Find max non-negative sub array from a given array [closed]

Task : Find out the maximum sub-array of non negative numbers from an array. The sub-array should be continuous. That is, a sub-array created by choosing the second and fourth element and skipping ...