Questions tagged [python-2.x]

Python 2 is the predecessor of Python 3 and its last version, Python 2.7 was formally released on July 3, 2010. Use this tag along with the main python tag to denote programs that are meant to be run on a Python 2 interpreter only. Do not mix this tag with the python-3.x tag.

Filter by
Sorted by
Tagged with
7
votes
1answer
366 views

Printing factors and prime factors of a number

I am a 46 year young newbie trying to learn programming for fun and adventure. I do this in my free time. Some very nice gentlemen on stackoverflow have sent me here. I wish that someone could review ...
3
votes
2answers
98 views

How to make my neural network train faster

I'm trying to train my neural network and for the most part it's going well. However, I'd like it if it could train faster and was wondering if anyone could give some advice. I'm trying mostly to ...
3
votes
2answers
440 views

Python 2.7 Powerball Game

This game allows one to either pick their own lottery numbers or have them generated and checks them with the most recent numbers, jackpot, and multiplier. I use concepts such as ...
6
votes
1answer
146 views

Simple CLI Python Hangman game

Preamble: I am very new to Python, and outside of Googling functions and a former work colleague telling me why I'm wrong, I have no formal training and haven't taken any "Learn Python" courses. I ...
5
votes
1answer
75 views

Sorting software version list using Python 2.7 (no modules)

I am participating in a challenge and one of the challenges was to write a script to sort a list of software versions (ex: 1.0, 1.3.2, 12, 1.3.0). Here is the my solution: ...
7
votes
2answers
1k views

Generate Letter Combinations of a Phone Number

The task: Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. and my solution: ...
1
vote
0answers
120 views

Quora upvotes trends Hackerrank challenge

The following code is my solution to an old problem I found today. Input Format Line 1: Two integers, N (1 ≤ N ≤ 106) and window size K (1 ≤ K ≤ N) Line 2: N positive integers of upvote ...
8
votes
2answers
57 views

Streaming scheduled TV shows according to a CSV playlist

I'm very new to Python, and I've made a small program/script that will allow me to stream specific files at a given time. My idea is that I have a .csv file for each day, with one row for each movie/...
3
votes
1answer
378 views

Noughts and crosses game for 2 players

This is my first program in Python that I have coded and I am relatively happy with how it turned out. I would like to know how I could make my code shorter and more efficient. ...
2
votes
1answer
83 views

Download the JSON from API and parse the data like Unique Voting Station Name and Councillors Name

Please give me some pointers on how I can improve this project with Python 2.7. ...
8
votes
1answer
456 views

Google FooBar “Prepare The Bunnies Escape”

I'm currently working through the google FooBar challenge, and I'm on the third level, in which I have to find the distance between the top left and bottom right points on a grid. The grid is filled ...
5
votes
3answers
265 views

Python lexicon class

First time around Code Review so please be gentle (and I am happy for comments on which angles of this post are a good fit and which less so). I'm not pretty much used to software engineering in ...
3
votes
1answer
122 views

A-Star Search with 3D Universe

I am attempting to write up a program in Python that will find the shortest path between two nodes in 3D space. The actual domain is the EVE-Online Universe, which is composed of systems connected by ...
5
votes
3answers
829 views

Text-Turn based dueling game

I have recently started to learn python, and I have made my first fighting duel game. I'm planning on adding more stuff in the future like shops and items so you get a way to spend gold, but for now ...
1
vote
1answer
50 views
9
votes
3answers
15k views

Convert list to a string with double quotes

For an external application I need to send a command as a string, like this: ["START", "1", "2", "3", "4", "STOP"] Note the double quotes! I create this command ...
1
vote
1answer
42 views

Create directories for outputs based on setting

I have a dict with a series of bools to specify if a particular aspect of my program will be run (e.g. settings['A'] and ...
2
votes
3answers
957 views

Given a sorted array nums, remove the duplicates in-place

I wrote an algorithm to solve this challenge but would love some feedback on its efficiency and, if you were an interviewer, what your opinion would be on my solution. I believe my time complexity is \...
10
votes
1answer
5k views

Given a string, find the length of the longest substring without repeating characters

I wrote an algorithm that solves this problem but I would love to get some feedback on it (especially since I'm not so confident in my Big \$O\$ skills). Do you think this is a good quality algorithm?...
3
votes
0answers
55 views

code for changing from old copyright to a new one in python

This code needs to get two inputs: one is the full address of a directory and another the file extension that it will be changed. These inputs cab be added in the default section of ...
4
votes
2answers
58 views

Pulling log messages from a MySQL table

I want to get this code reviewed for a function I wrote that pulls log messages from a MySQL table: ...
4
votes
1answer
6k views

Python script for monitoring systemd services (cpu/memory usage)

This is a python (2.7.13 according to sys.version) script that reads systemd service names from a file and gets their CPU and Memory usage. It does that by first ...
8
votes
2answers
813 views

Python vocabulary trainer for terminal

To train my Python skills I have made a vocabulary trainer which runs on a terminal: ...
6
votes
1answer
628 views

Calculate implied volatility for options on stocks and futures with two models

I wrote a code for a quant finance job and they told me that, besides it worked, it was poorly written. I asked for a more detailed feedback but they did not send it to me. I paste it here with ...
2
votes
0answers
661 views

PyQt frame which changes color with child focus

I am working on an application that has various "panels" contained within splitters. I wanted the panel border to change color when one of it's children gained focus. Here is a simple example of the ...
1
vote
1answer
138 views

Looping through a tree to get branch or leaf

This is my solution to a problem from MIT's 6.034 Artificial Intelligence course (see the heading Tree reference on 6.034 Artificial Intelligence, Lab 0). Can you please help me improve my solution (...
4
votes
1answer
2k views

Split a given number so that their sum adds to another given number

Task You are given a string S containing only decimal digits ('0' through '9') and a number N. Your task is to insert an arbitrary number (including zero) of plus signs '+' into S in order to ...
6
votes
1answer
128 views

Add an edge to a graph to minimize the average shortest path length

This program is used to find the nodes in a grid network, between which, if an edge is added, the average shortest path length of the entire grid reduces by the most. "Average shortest path length" ...
5
votes
1answer
435 views

Splitting URLs into hierarchy-level directories

The goal is to split a URL like http://q.com/a/b/c to: ['http://q.com/a', 'http://q.com/a/b', 'http://q.com/a/b/c'] My code: ...
9
votes
1answer
939 views

Simple cryptocurrency portfolio rebalancer

EDIT: the code has been changed significantly since the OP based on the first posted answer and some refactoring. Feedback on the general design of the app itself is still more than welcome. The ...
2
votes
2answers
132 views

Smart Mirror utilising python API's

I am making an object-oriented python project for a smart mirror running on a raspberry pi. The code receives input from API's, formats the data and displays it on the mirror. I would like to know ...
2
votes
0answers
52 views

Using zip to process widgets flagged as enabled

This code returns a list of widgets from spreadsheet ranges that are enabled for processing. The code works but it is poorly implemented, especially in terms of proper use of zip and layout. The code ...
4
votes
1answer
477 views

Relative frequency of words in tree of documents

I have a tree structure where at every node there is a list of documents (document length can vary from 5 to 500), and each document contains a number of words. I want to calculate relative frequency ...
1
vote
2answers
65 views

Reclassifying movies by theme

Any efficient way to solve the following problem assuming data is large. I solved the problem but how can I improve the code, which will make it efficient. any suggestions? Data: ...
6
votes
2answers
206 views

Convert csv to switch commands Python

The script should be a single python file that takes an excel file (or csv). Each row represents one switch. For each switch, there will be one or more interfaces. The objective is to output a ...
4
votes
1answer
297 views

Sort array into wave like array

I am solving interview questions from here. Problem : Given an array of integers, sort the array into a wave like array and return it, in other words, arrange the elements into a sequence such ...
1
vote
1answer
66 views

Find a number which equals to the total number of integers greater than itself in an array

I am solving interview questions from here. Problem : Given an integer array, find if an integer p exists in the array such that the number of integers greater than p in the array equals to p. ...
6
votes
2answers
353 views

Find the missing number and repeated number

I am practising interview questions from here. Problem : You are given a read only array of n integers from 1 to n. Each integer appears exactly once except A which appears twice and B which is ...
3
votes
1answer
984 views

Sum of absolute difference of values and corresponding indices of an array

I am solving questions on arrays from here. Problem: You are given an array of N integers, A1, A2 ,…, AN. Return maximum value of: f(i, j) for all 1 ≤ i, j ≤ N. f(i, j) is defined as |A[i]...
5
votes
2answers
924 views

Convert JSON from a webservice to text file

I get list JSON text from a webservice and list_of_columns is predefined, I need the output in that format. I am not sure about few things which are as follows I ...
2
votes
2answers
2k views

Heap Sort Implementation in Python

Objective: Create a heap sort that returns a unsorted list to sorted from greatest to least. Does this implementation look correct? Do you have any tips for optimizing this? ...
4
votes
2answers
1k views

Maximum sub-array of non-negative numbers

This is the "Maximum sub-array" problem from CodeChef: Find out the maximum sub-array of non negative numbers from an array. The sub-array should be continuous. That is, a sub-array ...
4
votes
1answer
429 views

Python image sequence file concatenation

I need to iterate over a large (in the thousands) list of files in a network folder and "concatenate" any image sequences into just one entry with the range of images (first image, last image in ...
2
votes
0answers
581 views

Recursively scrape links from web pages and check them

I'm new to programming and especially new to object oriented programming. I have built a web scraper using functional programming and am trying to build another using OOP principles. The overall idea ...
7
votes
3answers
154 views

Python methods to reduce running times KTNS algorithm

I have been trying to develop an algorithm called keep the tool needed soonest (for more information about the KTNS explanation (page 3)) but during the simulations, I have realized that it takes too ...
3
votes
1answer
304 views

python script to download multiple reports from odoo

We have an odoo server running (http://www.odoo.com/documentation/9.0/api_integration.html), which allows us to programmatically query and download invoice reports as PDF's We're running this on ...
3
votes
1answer
164 views

One minute cron Python script reads from MySQL and updates Redis based on calculations

The following code works and will be put into cron on a AWS server (not sure what specifications, cores, kernels etc) at a every 1 minute frequency. However, it's my first time putting a script into ...
4
votes
2answers
75 views

Bernoulli Sequence Lab

I'm writing some Python 2 code with which to analyze the compressibility of random bitstrings. It's working pretty well right now, and now I'd like to request some help making sure it follows PEP 8 ...
3
votes
2answers
105 views

Littlewood Polynomial Heatmap

The following Python program generates heat maps of the roots of Littlewood polynomials. It works fine with a small number of roots, however I tried to use 2^21 in the first loop and it ate up 12 ...