Tagged Questions
Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.
2
votes
0answers
15 views
CSV file parser and compare
This may seem like a lot of stuff? I just need help with 2 small parts the code works, however I have provided the rest of the info in case some one can help.
Code below is responsible for comparing ...
1
vote
1answer
15 views
Phone number/email regex verifier
Is there anything I can do better here? I tried looking for ways to simplify this with comprehension but could not figure out how and was told it is better to explicitly use ...
1
vote
0answers
21 views
Factoring a polynomial with integer coefficients
I haven't programmed in a while and need to improve my code in any way possible: efficiency, readability, etc. This program is for getting integer coefficients of any polynomial and factoring: ex.
$$ ...
1
vote
1answer
64 views
Pokemon search engine
I am making a simple function to find and match any possibilities what Pokémon the user wants. This is accomplished by taking in the input (what the user thinks the Pokémon is named) and compare its ...
2
votes
0answers
22 views
Strongly connected components in a graph: Kosaraju's algorithm
I implemented Kosaraju's algorithm on a graph with 800k vertices and 5100k edges.
The time taken by various operations are:
building graph took 11.84 seconds
ordering took 2.54 seconds
...
6
votes
3answers
566 views
Determine if a file is either in JSON or XML format
The purpose of this function is to determine if report_input_file is either in JSON format or XML format, this is what I came up with, just want to know if this is ...
4
votes
1answer
54 views
3
votes
2answers
348 views
Memoization with factorial in Python
I wrote a Python module to learn about memoization, and I have some questions on what I did.
How pythonic is this?
Does it make a difference if I used a class attribute instead of a function ...
2
votes
0answers
16 views
Generating public/private RSA key pair programmatically, using it for JWTs
In my app I'm using JSON Web Tokens for authentication purposes, using the pyjwt library. Instead of using static keys and/or worrying about key distribution, the server generates a public/private key ...
2
votes
1answer
192 views
4
votes
0answers
12 views
Python wrapper for Instagram API
This code wraps the user endpoint and media endpoint of Instagram API. Any best practices/ styles or glaring bugs you can see? I wrote some unit tests for each class but did not include for ...
12
votes
1answer
109 views
When it rains, it pours - August 2016 Community Challenge
1. Introduction
This code is my attempt at solving the August 2016 Community Challenge. Coming from a city where it rains cats and dogs on a daily basis this challenge was right up my alley =)
2. ...
3
votes
3answers
48 views
Reporting test results as JSON and XML
I have two functions now with very similar functionality, and would like to merge them into one more generic function. The only difference between those two functions is that one handles json input ...
4
votes
1answer
207 views
How to speed up PDF processing by PDFBox app jar
I want to convert a large PDF file into individual text files with PDFBox using Python.
Below is my code which takes lot of time to convert a PDF containing 1000 pages.
Is there anything I can do to ...
-5
votes
0answers
23 views
How to Iterate through a list of lists inside a dictionary and if present concatenate them [on hold]
Im very new to Python. The code might seem a little off.
{'id1' : [{ 'a' : ['hello', 'hi'] , 'b': ['Bye', 'Good-bye']}, {'a' : ['hello', 'hola'],'b': ['Bye']}], 'id2' : [{ 'a' : ['hello', 'hi'], 'b': ...
1
vote
3answers
64 views
Writing numbers into a file [on hold]
I'm taking my first ever CS class and I have an assignment due Friday. I just wanted someone to check my code.
Instructions:
Write a program that:
gets the name of a text file of numbers ...
5
votes
1answer
95 views
The Palindromic Odometer Puzzler: A Programmatic Solution
That is a programmatic solution to a puzzler from Car Talk, its summary is:
"I noticed that the last 4 digits were palindromic. I drove a mile,
and the last 5 were palindromic. I drove another ...
8
votes
1answer
43 views
A little text based adventure game
I'm writing a little text based adventure game, and wanted to know if there's anything I can do better thus far. It is not completed to don't get mad when it ends. I'm just curious as to better ways ...
4
votes
1answer
70 views
Simple chatbot written in Python
I wrote a simple chatbot in Python a while ago, and I'd like to know how it could be improved. Here's the code:
...
-3
votes
0answers
11 views
Trying to run k-means on pyspark on a dataset of 28 columns [on hold]
CODE:
from pyspark.mllib.clustering import KMeans, KMeansModel
clusters = KMeans.train(clustering_input,15,maxIterations=10,initializationMode="random")
ERROR:
Py4JJavaError: An error occurred ...
-4
votes
0answers
20 views
Testing if the arc between two (lat,lon) seapoints, intersect landmass [on hold]
I have the following problem: I have a bunch of points (latitude,longitude) that I know are located in the mediterranean sea. I have to check if the great circle path among each pair intersect the ...
1
vote
1answer
60 views
1
vote
2answers
68 views
Another Python prime-listing algorithm
I wrote a small program in Python that finds primes (how original) up to some limit. I tried to produce very clean code, so I'd be vary grateful if you could point out any improvement I could do to ...
1
vote
1answer
31 views
TLE in APS - Amazing Prime Sequence in Python at Spoj
This series is similar to Fibonacci Series defined as : a[0] = a[1] = 0 and For n > 1, a[n] = a[n - 1] + f(n), where f(n) is ...
2
votes
1answer
28 views
Dynamic Official Receipt increment algorithm
I made a function that would automatically generate official receipt for POS. it is able to accept format such as xxx, xxx-xxx, xx-xx.
But my code is really messy and horrible and it needs review. I ...
3
votes
2answers
49 views
Power flow analysis using the PSS/E simulation tool
The intro is a bit long. If you're not interested, then please read the update, and have a look at the specific parts I'm highlighting.
I'm very interested in any improvements, but you can assume ...
3
votes
1answer
35 views
Permutation index Python
Here is my Python code for finding the permutation index of a given digits and a target number. And by permutation index I mean, for example, given digits ...
5
votes
1answer
26 views
Testing file IO errors in python
Below is a simple class with two methods: the first calls open() to read in a file. The second calls the first method and does error handling.
There is also a ...
4
votes
3answers
55 views
Time Limit Exceeded for ETF - Euler Totient Function at Spoj
In number theory, the totient φ of a positive integer n is defined to be the number of positive integers less than or equal to n that are coprime to n.
Given an integer n (1 ≤ n ≤ 106), compute the ...
6
votes
2answers
56 views
Showing virus scan results from an API and a CSV file
I am utilizing an API module for interacting with virustotal.com in order to get AntiVirus results based of SHA256 hashes. The code I have is working but I feel like it can be improved greatly. I ...
3
votes
2answers
38 views
Capturing the positions of “start” and “end” markers in a multi-line string
Is there any better (and shorter) way to get index of a regex match in Python?
...
-2
votes
0answers
20 views
Python icmp tools [on hold]
I am developing ICMP tools package with Python. Currently I've implemented IPv4 ping using raw sockets.
The current roadmap is:
icmp traceroute
Simultaneous ping
ICMPv6
Documentation
Tests
https:/...
5
votes
0answers
56 views
Two versions of Sudoku
I have written two versions of a sudoku solver. Both can solve 9x9 sudoku boards in <200 ms. One of the implementations uses numpy. I am looking for feedback on both, but particularly on why my ...
3
votes
1answer
24 views
Django Create Profile Example
this is my first post here so I apologize if this already exists as I haven't gotten acclimated to the nuances of this website yet. I was creating a view with Django that would create a user profile ...
2
votes
2answers
92 views
Find if a part of the integer from another integer is divisible by 7?
The question states:
Given an integer A, and two indices Li, Ri. Find if the number from A which is bounded by the two indices is divisible by 7?
For example if A = 357753
indices Li = 3, ...
1
vote
2answers
55 views
Google Foobar Challenge: Spy Snippets in Python [closed]
I am getting all the answers correct. But still the solution is not accepted as only 4/5 tests cases are passed.
I have not posted the whole problem statement but the problem is similar to this.
I ...
3
votes
1answer
33 views
Emulating super() in Python 3.x using Python 2.7
Depending on the name of the first argument, self.__sup or cls.__sup behaves like super() in ...
1
vote
0answers
50 views
Moving a div inside p by to the body element
I get malformed HTML input with divs inside other HTML elements like the ...
7
votes
1answer
41 views
Steganography with AES encryption
I created a small program that hides arbitrary files in png images using steganography - it encodes the files in the two least significant bits of every channel, so using a 4-channel png we can encode ...
5
votes
0answers
40 views
Recursive vs non-recursive file/folder copy functions with optional replacement
Would someone else reading my code wish it wasn't recursive?
I'm writing a function to report file and folder copy errors. For now exceptions are being printed but they will be eventually sent to a ...
1
vote
1answer
16 views
Extract specified field value from filename using positional indexing
I have some filenames, and they each have data contained in them at specific locations in the string. I want a function that returns the value of the data specified by ...
6
votes
2answers
44 views
Todo-list practice code accepts title and list
I am new to OOP principles and best practices. People often say I write "unpythonic code," so give me your perspective on how to do things better.
...
2
votes
1answer
29 views
Stack implementation in Python 3
I'm learning Python by implementing commonly used data structures. My primary language is Java, thus would like to know if I'm being Pythonic enough. Any means to better up will be appreciated.
...
0
votes
1answer
35 views
Singly Linked List implementation in Python
I'm new to Python and thus learning it by implementing a set of commonly used data structures. Here's my implementation of a LinkedList.
First the Node class.
...
3
votes
2answers
75 views
“Hangman” game in Python
I have been using Python 3 to learn programming, and this is a very basic task, but I want to gain good programming patterns/habits at the very beginning.
...
-5
votes
0answers
19 views
Python Treap implementation [closed]
I know there are probably many problems with this (since I haven't tested it yet), but I'd appreciate any advice (stylistic hints as well).
...
9
votes
1answer
421 views
Palindrome-inize a number
For example if I start with the number 146. I first reverse it, so it becomes 641. Then I add this to the original number to ...
5
votes
1answer
65 views
Apriori algorithm in Python 2
This takes in a dataset, the minimum support and the minimum confidence values as its options, and returns the association rules.
I'm looking for pointers towards better optimization, documentation ...
-5
votes
0answers
18 views
Python3: Continuous variable update within Mainframe [closed]
Basically, I have created a thread which continuously writes a global variable in an infinite loop. Then I have the mainframe which should read and display that variable.
The problem is that once the ...
-3
votes
1answer
21 views
Inner function accessing variables directly from outer function scope - What are the drawbacks? [closed]
I saw this snippet in a code that I am working on. And I feel that accessing the outer function variable directly in the inner function brings some undesirable magic. For e.g. when I read the function,...