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
3 votes
2 answers
3k views

Python battleship program (2 player or 1 player)

I recently started studying python with a much heavier study regimen, I wanted someone to review my code to see what they thought. I do have a to do list at the start of the code so any tips on how I ...
11 votes
3 answers
4k views

Removing entries from a dictionary containing bad words

I have a dictionary with each item containing a quote in another dictionary: ...
  • 305
14 votes
1 answer
11k 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 ...
  • 275
6 votes
1 answer
915 views

Printing bowTie pattern in efficient and pythonic way

I've posted code/library to GitHub for first time over here. The code is pretty simple. It generates a BowTie pattern of given size and characters. I did attempt to implement DP by calculating only ...
  • 163
10 votes
4 answers
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. ...
  • 103
2 votes
0 answers
725 views

Python scapy subnet mapper

This a follow-up question of Python scapy - TCP port scan of subnet I've decided to make an all powerful subnet mapper in Scapy to better understand how tools like ...
  • 11.5k
2 votes
1 answer
9k views

Computing the powerset of a list

I've written the following code for computing the powerset of a list (we consider the list has all distinct elements, although it doesn't really matter). Can this function be further optimized? <...
3 votes
2 answers
3k views

Create all possible character combinations of any size

I am trying to create all possible character combinations of a given word. For example, “laptop” will include the following possible combinations: ...
1 vote
1 answer
277 views

Greedy Algorithm - Tuple Comparator

I've completed the problem set 9 of the OCW 6.00sc course which requires the implementation of a greedy algorithm - see prompt. When completing problem 2, it is asked to implement comparator ...
  • 131
3 votes
1 answer
487 views

Iterative binary search

I have made a simple binary search algorithm with the assumptions that the input array is sorted and has only unique values. ...
  • 183
3 votes
2 answers
3k views

Calculate True Positive, False Positive, True Negative and False negative and colourize output

Objective : Calculate True Positive, False Positive, True Negative and False negative and colourize the image accordignly, based on ground-truth and prediction from my classifier model. Problem : ...
user avatar
5 votes
1 answer
2k views

Python scapy - TCP port scan of subnet

Question I love using NMAP and other related tools to scan networks really fast. But using a tool and understanding how it works are 2 different things, thus I tried creating a program where I can ...
  • 11.5k
2 votes
0 answers
869 views

Optimization Resource File for Robot Framework

I'm looking for optimization between these files, and simplification. If something already exists to do what I have a keyword do, I'd like to know about it. Loops.py is located in one of my other ...
1 vote
2 answers
1k views

Find count of alternating numbers

What I am trying to do is to find count of alternating numbers such that it alternates with -ve and positive sign for e.g.: 1 -2 3 -4 would get me 4 3 2 1 as from 1 to -4 including the two numbers ...
5 votes
0 answers
201 views

Code for training machine learning linear regression and SVM

Ok , for my final year project I've wrote this piece of code to train my machine learning model on a this dataset , here the code i used ...
1 vote
2 answers
465 views

Read n lines, and count the lines that do not contain the string "CD"

I would like to know how to improve the execution speed of the code below. The context : n is an integer read from the stdin, and represents the number of cases. Each case is represented by a ...
3 votes
0 answers
362 views

Python2.7 Some xor fun

After doing the Cryptopals challanges, which I found scrolling through codereview, and finally being able to solve set1 challenge 6. I decided to have a little xor fun, and make an automated xor ...
  • 11.5k
4 votes
2 answers
4k views

Reversing substrings in parentheses

Problem: The task is to reverse the strings contained in each pair of matching parentheses, starting from the innermost pair. The results string should not contain any parentheses. Example: ...
3 votes
2 answers
2k views

Python image encryption security analysis

I'm currently seeking someone to review the source code for an image encryption program in Python 2.7. The code is complete and should run provided you have installed the correct packages. For this ...
  • 1
2 votes
2 answers
7k views

Finding an increasing sequence from a given array in a time-efficient manner in Python

Problem Statement: Given a sequence of integers as an array, we have to determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the ...
5 votes
1 answer
299 views

Collating list of dicts to table format

I've got a list of dicts, data, that updates periodically and is persisted to a database. Every time data is updated, the gui ...
  • 267
3 votes
2 answers
702 views

Merging the frequency rankings of boys' names and girls' names

Problem statement: The html pages for each year which represents the top 1000 most common Girl and Boy names in the order of their frequency are ranked and provided. And they are ranked based on the ...
5 votes
1 answer
15k views

Removing key/value pairs in list of dicts

I have a list of dicts that all have the same keys. If a key's value is None in all dicts then I want to remove them (A solution that creates a new dict is fine as ...
  • 267
3 votes
1 answer
71 views

Streamlining series of try-except + if-statements for faster loop processing in Python

I'm processing strings using regexes in a bunch of files in a directory. To each line in a file, I apply a series of try-statements to match a pattern and if they do, then I transform the input. After ...
5 votes
3 answers
2k views

Beginner Tic Tac Toe game in Python

I've just started learning python and I tried making a tic tac toe game and would really appreciate it if I got some feedback. I know, my code isn't the best optimized but this is what I could come up ...
  • 51
2 votes
2 answers
1k views

Compare two files and save the result into a pickle file

My code should compare two vectors saved as dictionary (two pickle files) and save the result into a pickle file too. This works but very slowly. For one compare result I'm waiting about 7:20 min. ...
4 votes
2 answers
550 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 &...
  • 151
5 votes
2 answers
1k views

Prime Number Generator (6n + 1 or 6n - 1)

This generator is like most where it brute forces an integer: it see whether the integer is divisible by any of the primes; if so, then it's not a prime and vice versa. This though only compares ...
8 votes
3 answers
2k views

Replacing English words in a string with their Spanish equivalents by dictionary lookup

I want to improve my code's performance and running time, looking for write my loops better. For example, I have a dictionary that contains words as keys, and their translation in Spanish as values. ...
  • 81
5 votes
1 answer
104 views

Saving web search results for EANs to CSV

This is my first program in Python. Following code is taken from different posts (mostly this site) and combined together so that I can automate my routine task. It's working properly but I need ...
  • 51
8 votes
3 answers
3k views

Function to censor single word in a sentence

The following function censors a single word of choice in a sentence with asterisks, regardless of how many times the word appears. How can I further simplify this code? ...
  • 171
6 votes
2 answers
5k views

Implementation of Sieve of Eratosthenes in Python

The following is my implementation of Sieve of Eratosthenes. Can somebody please review it? Am I adhering to the algorithm and is it a reasonable implementation of it? ...
1 vote
1 answer
2k views

Python selenium object repository

I was trying to create the selenium web element object repository in python. I have come up with three ways to do so. However, I am new to python so I am not sure which one is better than other. ...
0 votes
2 answers
15k views

Invoking functions using a function pointer approach [closed]

I re-used this answer from this StackOverflow answer to simulate a function pointer approach available in high-level languages like C. While using this approach in Python, the dictionary I am ...
  • 159
7 votes
1 answer
758 views

Python 2.7 Tower of Hanoi game with ASCII graphics

The game generates a fixed, "animated" game board via ASCII characters that is reprinted and cleared after each valid move. The format of the input for making moves is described in the script. You ...
5 votes
1 answer
295 views

AIO programming challenge - Friendlist - Who has the most friends?

I attempted this sample question from the Australia Infomatics Competition. TL;DR - Each line of input contains two numbers, representing a mutual friendship relationship. The output needs to be the ...
  • 171
2 votes
1 answer
528 views

Load data in sqlite

I have written small application for inserting data into sqlite. can you please review. create data from specified path create Table into sqlite database Path format /user/proj/file ...
3 votes
5 answers
127 views

Product iteration while checking for overlaps

This is an extended question to the following question I posted Class scheduling tool with image output Context of previous question: I have a multilayered dictionary that contains information ...
  • 211
3 votes
1 answer
545 views

Using os.path.join in Python

I want to reduce/shorten this part quite a lot. If you see that a method can be reduced or even erased please do not hesitate to suggest that. Any answer that rescue the code would be great. ...
  • 101
6 votes
1 answer
145 views

Simple application in Python using OpenCV for face

I have been working on a simple Python application for face recognition with OpenCV. My code does its work and gets the job done, but I'm wondering if there's a 'better' way to do this. I hope I can ...
  • 63
5 votes
3 answers
1k views

WV lottery tool in Python

I am self taught in python. I love to play the lottery and play with numbers. I put this program together as a hobby to learn python and build something that people can use. I used and reused code ...
  • 51
4 votes
2 answers
166 views

File's encryption tool in terminal

I've created a wrapper for the SimpleCrypt library that allows to easily encrypt/decrypt a string. The application is used this : ...
  • 12.3k
6 votes
3 answers
248 views

Class scheduling tool with image output

I have a multilayered dictionary that contains information about classes. I am using this to code an automatic schedule builder that I will eventually add to a separate Tkinter application I made that ...
  • 211
4 votes
1 answer
615 views

Console Tic Tac Toe

So I started Python this week, and I never programmed a game before. Even though Tic Tac Toe is probably the simplest game ever, I had some challenges while coding the game rules. I split my project ...
  • 12.3k
7 votes
1 answer
287 views

Dynamic Programming with Project Euler problem 67

I am a beginner with python and programming in general. I started teaching myself about 2 months ago. I've been working my way through Project Euler and a few similar sites to build my chops, and ...
  • 73
1 vote
3 answers
1k views

Simple Blackjack game in Python 2.6.9

Like the title says, I made a very simple game of Blackjack using Python version 2.6.9. I am relatively new to python and programming so I would really appreciate some constructive criticism to help ...
3 votes
1 answer
192 views

My images have secrets A.K.A. the making of aesthetic passwords V.2

This is my implementation of a prng steganography tool written in Python. You can also find the code on GitHub. Steganography is the art of hiding messages in (images, videos or even audio) I've ...
  • 11.5k
8 votes
2 answers
12k views

Python code that compares two files byte by byte

I wrote a Python (2.7) script that compares a file byte by byte. filecmp was not suitable for the application because it compares metadata as well. How can I ...
  • 275
16 votes
1 answer
24k views

Decorator to measure execution time of a function

This decorator adds the elapsed time to a function's attributes when applied. My concerns: Is the code pythonic? Could this code be useful? Should I just use the ...
  • 1,695
2 votes
1 answer
267 views

Reverse shell allows connection between computers

I've recently made a reverse-shell which allows you remote shell access to other computers. It's written in Python 2 and it is cross-platform. Basically, it get's user input for a command and sends ...
  • 203

1
3 4
5
6 7
25