Use this tag if you are specifically using Python 2.7. Such questions should be tagged with [python] as well.

learn more… | top users | synonyms

5
votes
2answers
42 views

Python traverse a directory recursively and print contact numbers

I am writing a python code to recursively traverse a directory containing only text files and then print the 10 digit Indian phone number and all its variants. I am very new to python and I have ...
1
vote
1answer
43 views

4 sum challenge (part 2)

This is a continued discussion from (4 sum challenge) by return count only. Problem Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[...
1
vote
0answers
33 views

Longest absolute path in file system

Problem Suppose we abstract our file system by a string in the following manners: The string dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext represents: ...
2
votes
3answers
157 views

Different path for grid move (part 3)

This is a continued discussion from (Different path for grid move (part 2)) to optimize for space complexity (using only cur list, other than a ...
4
votes
0answers
73 views

4 sum challenge

Problem Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero. To make problem a bit easier, all A, B, C,...
4
votes
3answers
89 views

Two sum with two lists

Suppose we have two sorted lists, and we want to find one element from the first, and the other element from the 2nd list, where the sum of the two elements equal to a given target. If there are ...
2
votes
3answers
81 views

Different path for grid move (part 2)

This is a continued discussion from (Different path for grid move) to optimize for space complexity, and since it is new code and I make a new post. Given a m * n grids, and one is allowed to move ...
5
votes
1answer
51 views

Small Python script using Google and Slack APIs

I've recently been working on a small Python script that I was tasked to do at my new job. It will basically handle the rotation and notification of the on call engineer by populating a Google ...
2
votes
0answers
61 views

Implement SGD of the softmax regression with only numpy

I am implementing the stochastic gradient descent algorithm. I think there is plenty of room for improvement. ...
5
votes
1answer
63 views

Number to Roman Numerals in Python

I recently started learning python. Requirements Input: Integer between 1 and 3999 Output: String with Roman numerals I would appreciate it if someone could have look at the code and give me any ...
4
votes
1answer
84 views

Different path for grid move

Given a m * n grids, and one is allowed to move up or right, find the different number of paths between two grid points. My major idea is, if move r steps right, <...
1
vote
1answer
52 views

Balanced smileys check algorithm

Problem Your friend John uses a lot of emoticons when you talk to him on Messenger. In addition to being a person who likes to express himself through emoticons, he hates unbalanced ...
2
votes
0answers
54 views

Thread-safe RLockedList

I have written a thread-safe list which can be used as a drop-in replacement for a regular list. This has been tested and used internally without issue, but "The absence of evidence is not evidence of ...
-3
votes
0answers
41 views

how many zeros from 1 to 1000000 [closed]

If you write out all of the integers from one to one million, how many zeros would you write? program pseudo-code: ...
2
votes
1answer
34 views

Arcpy script to check for TIFF files and add them to different lists

My script goes through sub folders in my main directory and based on a wildcard checks if a tiff file exists or not, if it exists then the file path is appended to the corresponding list. For example, ...
3
votes
0answers
38 views

Counting squares in a grid that is subdivided by line segments

Problem: Given a picture of square with a bunch of horizontal and vertical lines in it (lines are not necessarily spanning the full square length, in other words think of a fine grid with many ...
2
votes
1answer
130 views

Calculate stock portfolio profit based on CSV data

import time import csv import argparse from nsetools import Nse from colorama import Fore nse = Nse() t = time.time() CSV file contains the following data, I ...
5
votes
1answer
86 views

Find equal pairs

Problem Given an array A of unique integers, find the index of values that satisfy A + B =C + D, where A,B,C & D are integers values in the array. Find all combinations of quadruples. I ...
3
votes
3answers
67 views

Continuous sequence against target number

Post problem and my code written in Python 2.7. Any advice for code bugs, performance in terms of algorithm time complexity and code style are appreciated. I did PEB8 self-check in PyCharm. BTW, a ...
3
votes
0answers
35 views

Tarjan's strongly connected component finding algorithm

Here is my code for Tarjan's strongly connected component algorithm. Please point out any bugs, performance/space (algorithm time/space complexity) optimization or code style issues. ...
5
votes
0answers
41 views

K-Means clustering in Python2

I've implemented the K-Means clustering algorithm in Python2, and I wanted to know what remarks you guys could make regarding my code. I've included a small test set with 2D-vectors and 2 classes, but ...
2
votes
2answers
38 views

Fastest way to count combinations of values from two lists/arrays

I have a file with mostly 0 and 1. For each line I would like to compare it against all others (without the redundancy) and count the different combinations. It is slightly more complicated as there ...
8
votes
0answers
107 views

Download images from an image board based on tags and blacklists

This code is meant to download images from an image board to create a local backup. Images are grouped by tags selected by the user and then downloaded using multiprocessing. Normal use of this ...
8
votes
1answer
748 views

Scraping GitHub for security vulnerabilities

I haven't done much Python programming, but I really like the language so I've been using it for side projects that I work on. The problem with this is that I don't have the opportunity to have my ...
1
vote
1answer
49 views

Tower of Hanoi: graphical representation of optimal solution

I wrote a program to show graphically the solution of the problem of the Tower of Hanoi. Here is a video of an example run. The logic of the solving is taken from StackOverflow (see links in ...
1
vote
1answer
60 views

Reverse double linked list in python 2.7

Problem is straightforward, reverse a double linkedlist, any advice on functional bug, performance in terms of algorithm time complexity and code style are highly appreciated. Code written in Python ...
6
votes
1answer
183 views

Check if two rectangles overlap

Suppose rectangles are parallel to x-axis/y-axis. Check if two rectangles overlap or not and if they do, output the overlap area. Here is my code and I track min/max x-coordinate and min/max y-...
3
votes
0answers
50 views

Vertical sum in a given binary tree

I'm working on this problem, Problem statement, Given a Binary Tree, find vertical sum of the nodes that are in same vertical line. Print all sums through different vertical lines. Examples: ...
3
votes
1answer
76 views

2D Vector class

As part of a game engine I am creating, I am in the process of writing a bunch of math classes (vector2/3/4, matrix2/3/4, and quaternions to start with). Vec2 ...
3
votes
1answer
40 views

Simulating a game of signals

The following code simulates a game of signals in which four participants (playing in pairs) show (muestra) and see (observan) signals. Signals are randomly assigned in the first round. Signals in the ...
12
votes
3answers
158 views

Maximizing grad student happiness

A local university's graduate school has a field placement that's a required component for graduation. Each student works in the field (something like a residency for medical students) for one year ...
3
votes
2answers
81 views

Script to activate an alarm at a time in the future

I am making a flashlight plugin for macOS. Here is the main code, plugin.py, the method results gets called first and is passed ...
2
votes
2answers
100 views

Find two numbers that sum closest to a given number

I'm working on the problem of finding 2 numbers that their sum is closest to a specific number. Input numbers are not sorted. My major idea is to sort the numbers and find from two ends. I'm ...
7
votes
3answers
73 views

Find all needles in the haystack and return their sum

This is based on a programming challenge I recently solved. However, since the writer of the challenge asked me not to disclose the question and/or it's answer, I modified it a little. If it doesn't ...
1
vote
0answers
69 views

Minimal number of airplanes needed

I'm working on a problem of finding the minimal numbers of airplanes needed, given the schedule of each flight, while schedules may overlap. For example, schedule (0,1) means a flight starts at clock ...
1
vote
1answer
45 views

Find smallest subset prefixes (part 2)

Here is my code for this problem. Any bugs, performance in terms of algorithm time complexity, code style advice are appreciated. This is a continued discussion from (Find smallest subset prefixes) ...
2
votes
1answer
65 views

JSON pretty print

Here is my simple program to pretty print a JSON object. I'm looking for advice of better pretty print solutions, functional bugs, code style and algorithm time/space complexity improvements. BTW, I ...
4
votes
3answers
60 views

Check if all of the delimiters in an expression are matched and closed

Problem Write an algorithm to determine if all of the delimiters in an expression are matched and closed. {(abc)22}[14(xyz)2] should pass ...
5
votes
2answers
51 views

A command-line utility to solve a system of linear equations

I was re-checking my answers for a Math paper on my laptop. I needed to verify my solution for a system of linear equations. Unfortunately, I found no quick way to do that. That's why I wrote a (...
4
votes
2answers
132 views

Bubble Sorting Algorithm

I made a simple Python program which takes a list of unique numbers and orders them from smallest to greatest. The algorithm (which is actually quite similar to bubble sort) works like this: Take the ...
7
votes
1answer
76 views

Wrap a long string to an array of short-enough strings

I have made a function that wraps text in pygame (i.e. it turns a long string into an array of smaller strings that are short enough so they fit within the given width when rendered in the given font)....
1
vote
1answer
49 views

3 sum implementation in python 2.7

Working on below problem, looking for advice on code style, functional bug and time complexity improvements. Also looking for advice in, If array is not sorted, any solutions available for O(n^2) ...
4
votes
1answer
159 views

Print linkedlist reversely

I'm working on the problem of print a linked list reversely without destruction. I'm wondering if any other better ideas, in terms of both time complexity improvement and space complexity improvement. ...
2
votes
2answers
120 views

Find smallest subset prefixes

Here is my code for this problem. Any bugs, performance in terms of algorithm time complexity, code style advice are appreciated. The areas which I want to improve, but do not know how to improve are:...
5
votes
2answers
53 views

Apostle Galaxies: dict subclass with disk caching

I am an astrophysicist working on large simulations as part of the APOSTLE project. The output of the simulations I use are large (TBs) and are stored in tables spread across multiple hdf5 files. ...
4
votes
1answer
83 views

Determine how many unique numbers there are in a text file

I have a program that has one job: to determine how many unique numbers there are in a text file. The text file contains a string of numbers created by this other program named ...
3
votes
0answers
82 views

subprocess with logging module: tee with StringIO

I've got a long-running process. Once it finishes I need the output. But the user should be informed as its running. With the logging module I get timestamps and ...
6
votes
2answers
95 views

100 Locker Problem Expanded

The locker problem for 100 lockers is simple: A school has 100 lockers and 100 students. All lockers are closed on the first day of school. As the students enter, the first student, denoted S1, ...
3
votes
2answers
76 views

Returning largest product of longest subsequence between min and max

This function returns the largest product of all elements of a list between the leftmost and rightmost min and max elements. Is there more readable and maybe compact way to rewrite the ...
-2
votes
1answer
42 views

Better way to write algorithm, possibly recursive [closed]

I wrote the following code: ...