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
1
vote
0answers
136 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
159 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/...
2
votes
0answers
1k 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 ...
3
votes
1answer
626 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. ...
3
votes
2answers
3k views

Given an unsorted integer array, find the first missing positive integer

Here is the problem, any advice about code improvement, more efficient implementation in terms of time complexity, functional bugs, etc. are appreciated. Given an unsorted integer array, find the ...
10
votes
1answer
4k 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 ...
4
votes
1answer
271 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 ...
1
vote
1answer
458 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 (...
5
votes
3answers
1k 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 ...
4
votes
1answer
17k views

Extracting the text of a specific XML node

I have to extract friendlyName from the XML document. Here's my current solution: ...
5
votes
1answer
617 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: ...
1
vote
1answer
51 views
10
votes
3answers
26k 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
2answers
440 views

Very simple number guessing game

I created a simple 15-line number guessing game in Python 2.7: ...
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 ...
3
votes
0answers
61 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
63 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: ...
8
votes
2answers
1k 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
795 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 ...
3
votes
1answer
411 views

TapeEquilibrium Codility implementation not achieving 100%

Given the following task description from here : A non-empty zero-indexed array A consisting of N integers is given. Array A represents numbers on a tape. Any integer P, such that 0 < P &...
4
votes
1answer
4k 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 ...
9
votes
1answer
2k 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 ...
3
votes
3answers
470 views

Creating and manipulating FITS files

I wrote a program that manipulated data from VLA observations and created FITS files to be used in creating spectral energy distributions of high redshift radio galaxies. I really tried to be as ...
10
votes
4answers
1k views

Accepting user input for tickets and tips

I've done tutorials as well as searches. I need assistance in simplifying this code. Please don't do it for me- instead inform me of what, where and why you are trying to simplify or write less code. ...
2
votes
2answers
16k views

Using BFS to solve 8-puzzle game using Python 2

I'm trying to solve the 8-puzzle game using BFS, DFS and A* algorithms implemented using Python 2.7. For now, I have managed to solve a couple of test cases using BFS and I want to know how I can ...
2
votes
3answers
469 views

Simplify definition of a dictionary with default return value

I need a constant (dictionary with values and default return value if there are no defined value for a key). Searching for any ways to simplify the code. Without a default value I can simply define a ...
2
votes
2answers
206 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 ...
4
votes
1answer
5k views

matplotlib get_legend_handles_labels always return empty

I have a problem when adding elements to the same figure. The problem is with the legend. At each iteration I add elements and the corresponding legend. But I want the legend to include all the ...
2
votes
0answers
55 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 ...
6
votes
1answer
2k views

Sparse matrix compressed sparse row (CSR) in Python 2.7

Brief introduction for CSR: The compressed sparse row (CSR) or compressed row storage (CRS) format represents a matrix M by three (one-dimensional) arrays, that respectively contain nonzero ...
4
votes
1answer
642 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 ...
3
votes
1answer
5k views

Name Banner Program

I have a program that takes an input from the user (the user's name) and print a result with their name inside a border such as: ...
6
votes
1answer
16k views

Converting embedded JSON into flat table

I am new Python user, who decided to use Python to create simple application that allows for converting json files into flat table and saving the output in cvs format. I was wondering if you could ...
12
votes
1answer
8k views

Farthest point algorithm in Python

I am learning Python and I tried to do a program to find K points from a set of N points, farthest as much as possible (I'm not ...
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: ...
5
votes
2answers
1k 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 ...
6
votes
2answers
531 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 ...
3
votes
1answer
540 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
86 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
391 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 ...
2
votes
1answer
1k 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]...
1
vote
1answer
148 views

Translating a Haskell data to Python

I've been working on a project in python, and I needed to represent a certain numeric type. I need to represent the concept of some or all. Then I need to be able to add these amounts. Coming to ...
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
1answer
899 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 ...
3
votes
2answers
2k 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 ...
7
votes
3answers
157 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
2answers
354 views

GUI interface for company specific calculator

I created a customised GUI application in Python, which is a calculator that does some basic functions for my company. I would like to ask you for overall suggestions for code improvement. ...
2
votes
0answers
819 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 ...
6
votes
2answers
35k views

Binding a keyboard key to a Tkinter button

I'm specifically asking about binding a keyboard keystroke to a button in a GUI. Originally I planned to bind the keystroke to the GUI button itself, but that seemed impossible, and potentially unwise ...
4
votes
1answer
559 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 ...

1
3 4
5
6 7
25