Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.

learn more… | top users | synonyms

0
votes
0answers
4 views

Dynamic Django class based views for multiple profile form selection

I'm still fairly new to Django, so I feel that I may have approached this problem the wrong way. I more or less just brute forced the problem of being able to dynamically handle my form types. ...
0
votes
0answers
41 views

Storing a version number in a Python project

If I have this simple structure: $ tree . └── project ├── __init__.py └── my_script.py where I want to define ...
-4
votes
0answers
29 views

Python rock, paper, scissors code [on hold]

First post here so excuse any formatting mistakes. So I had to create a game in Python for school so decided to make a text-based rock, paper, scissors game. The code seems to look correct but the ...
3
votes
2answers
67 views

Assembling edges of a graph

I'm making a neural network that comprises five populations of feature-selective neurons and one population of non-selective neurons. Each neuron in this network receives connections from c * f * ...
3
votes
2answers
54 views

Beginner code for a Rock, Paper, Scissors game in Python

I am a beginner in Python and I wanted to see if I could get some feedback on my simple Rock, Paper, Scissors game. I do have previous experience in programming, as I started learning a few years ago ...
0
votes
0answers
26 views

Reverse integers divisible by 3 [on hold]

I was asked a pretty basic question in a recent interview. Given a integer string , reverse the integers that are divisible by 3. Here is an example. "1234567890" becomes "1204597863" I was rejected ...
2
votes
1answer
51 views

Check binary tree symmetry by reversing, checking equality, coverage tested, makefile

A few weeks ago I recall a HackerNews story (found it again: "I Don't Want to Hire You If You Can't Reverse a Binary Tree") about reversing a binary tree (with, as I remember it, the end goal being to ...
-1
votes
0answers
13 views

Trying to conduct Python machine learning on data that is tuple [on hold]

I'm a newbie to Python. I'm trying to conduct machine learning on a csv dataset, using sklearns. My problem is that I cant read my data, since opening my csv file and reading it with pandas renders it ...
-4
votes
0answers
23 views

Could anyone find a bug in my code for finding whether the graph is BIPARTITE or not ? [on hold]

I am solving this problem on spoj. The problem essentially tells to find whether graph is bipartite or not. I have written the code and tried many(really many) test cases but it seems to work ...
4
votes
2answers
45 views

Rod-Cutting Problem using dynamic programming

I wrote the following code for solving the Rod-Cutting Problem using dynamic programming: Rod Cutting Problem: Given a rod of length n inches and an array of prices that contains prices of all ...
-6
votes
0answers
28 views

traverse through binary tree and print list [on hold]

New here! Trying to traverse through a binary tree in level order (breadth first traversal). I have written code but I get a different output to what is desired. The tree ...
3
votes
1answer
63 views

Python program to lock and unlock files

The code takes srcPaths and actionType as parameters. The former is a string with tab-delimited file paths, while the latter is ...
1
vote
0answers
17 views

Python html Page reporter

My program, page_reporter, attempts to port scan a network and identify servers hosting web pages. From here it will create an HTML report using iframes to give you a snapshot of what the page looks ...
6
votes
1answer
56 views

Histogram of a string

I'm teaching myself Python and when a friend posted this sentence Only the fool would take trouble to verify that his sentence was composed of ten a's, three b's, four c's, four d's, forty-six ...
4
votes
1answer
109 views

Maximum profit from buy and sell offers

Given a list of sell offers and a list of buy offers for an item I want to determine how many units to trade for maximum profit. Each offer consists of a price and a maximum amount of units being ...
3
votes
2answers
58 views

Check that files don't contain Unicode

I use this code to check that all files in a directory are free from Unicode and non-printable characters. Can I improve the structure of the code? ...
8
votes
1answer
49 views

Small Python class for Lindenmayer Systems

L-systems are basically rules for recursively rewriting a string, which can be used to characterize e.g. some fractal and plant growth. I wrote a small class to represent deterministic L-systems and ...
3
votes
1answer
28 views

simple form validation

i've just started to learn python /django .. im coming from php world ...i mostly struggle with None values which are new to me .. in php i mostly did my boll checking with true/false but in python ...
3
votes
0answers
18 views

How to properly set a different formatter for a specific logger's child?

For certain modules or functions, I want to have a different format for the logged messages. I have done this in a way that looks a bit hacky: I have set a special Logger, containing a special ...
-1
votes
0answers
37 views

Iterating through a list of lists of tuples [closed]

I have this function neighbor that works on this matrix: ...
3
votes
2answers
183 views

Printing all prime factors of a number input by the user

I just started teaching myself to code a few days ago using the Euler problems. I finished a variant of problem 3: print the prime factors of a number input by the user. I just want feedback and code ...
5
votes
2answers
73 views

Writing a hiveserver2 query result to CSV with Python using pyhs2

I am trying to create a small application that will help me extract data from Hadoop via hiveserver2 by simply writing it to CSV. At the moment, it takes about 40 seconds to pull 10,000 records from a ...
1
vote
1answer
128 views

A simple Hangman game in Python

I'm a noobie in programming so I've made a simple hangman game in python and I'd like someone to tell me how I could improve the code. edit:How could I do it using classes? ...
5
votes
1answer
82 views

Koch snowflake in Python with numpy and pygame

I've drawn a Koch snowflake with Python 3. I'm new to the Python world and would appreciate all feedback on how to make the code more Pythonic as I'm not used to these idioms, styles and modules. All ...
4
votes
0answers
42 views

Matrix of heights test

I was writing a program for my math class because my Professor asked me to. The problem is as follows: 300 people are arranged in 30 rows each of 10 people. The tallest of each row is chosen, and the ...
1
vote
2answers
87 views

Argument parser for a PostgreSQL backup utility

I'm sure it's still not yet perfect and tips will be greatly appreciated! I just re-read the script and I realised I'm not handling exceptions! The script is unfinished but I'm looking for WIP (work ...
2
votes
1answer
39 views

Flatten a nested dict structure in Python

For some post-processing, I need to flatten a structure like this ...
2
votes
1answer
53 views

Beating a dead horse: Project Euler 4

The task A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the ...
1
vote
3answers
58 views

Python static / instance method or function?

background: I have a model called FileInfo, which represents a sftp file / windows dfs file. ...
3
votes
1answer
36 views

Python 3 class constructor

I have implemented a metaclass in Python 3 that, apart from the usual instance constructor (i.e. __init__), enables you to define a class constructor (as a class ...
3
votes
1answer
68 views

Finding the maximum distance from the starting node

I've tried everything to make my program faster but with 250 nodes my code takes around 9 seconds to print the result, and with 5000 nodes it took around 260 seconds. Is there a way to make my ...
11
votes
2answers
185 views

Python 3 decompression routine 10x slower than C# equivalent

I'm relatively new to Python 3, especially IO programming, writing a Blender add-on to import model data. The model data is available in a custom compression, and I originally wrote code in C# to ...
5
votes
2answers
50 views

Processing a sequence of additions and deletions

I am working on a program which manages a list, and must be able to insert new items, and delete ranges of items. I want the user to be able to specify the insertions and deletions in terms of the ...
1
vote
2answers
57 views

Counting pairs of integers which have a predefined difference

I'm doing this HackerRank problem: Given \$N\$ integers, count the number of pairs of integers whose difference is \$K\$. So far, I've ended up with this code: ...
4
votes
2answers
70 views
+100

Find group of available stalls in an aisle

An aisle is defined as two rows of six stalls each. A stall is adjacent to another if it is directly next to it or across from it. My method finds out how many stalls can be found in a chain from ...
6
votes
2answers
158 views
+50

Dictionary as context manager

I've created a class that implements customized addition, subtraction, etc. But for this class I'd like to have some additional parameters for these methods (...
0
votes
2answers
62 views

google foo.bar max path algorithm puzzle optimization [closed]

I got a programming puzzle described as follows: Save Beta Rabbit Oh no! The mad Professor Boolean has trapped Beta Rabbit in an NxN grid of rooms. In the center of each room (except for ...
-1
votes
0answers
21 views

How to store bought digital goods in django [closed]

I'm building digital goods shop. Goods are like software keys, could be bought only once. I want users to have personal page with their goods. Currently I store this relation information in ...
7
votes
0answers
84 views

The YouTube crawler

I have coded a program to scrap YouTube data (for educational purposes). When the link of the channel is entered it scraps the channel name, description of the channel, the videos posted by the ...
5
votes
1answer
71 views

Simple code-golf programming language written in Python

I've written a "simple" interpreter for a programming language in Python, called Tellurium (named after the element of the same name). So far, it's working pretty well, but there are some things I'd ...
1
vote
0answers
14 views

ChiSquare test Code in Python

I was trying to write a code from scratch for Chi-square test.This is the code that I had written in python using pandas.I had a doubt whether the code can produce the desired output or can be written ...
0
votes
1answer
69 views

Calculate the arclength

I am trying to estimate a good approximation for the arclength of the curve \$ y = \sqrt{1-x^2}\$ for \$x \in [0, 1]\$. I did this using a Bezièr curve, and made it so that the area under the two ...
2
votes
1answer
33 views

Calculate the lattice paths in an n*n lattice (Project Euler #15)

Project Euler #15 is to find out all the distinct possible ways there are to move from the first point (1,1) to point (n,n) in an n*n lattice. ...
4
votes
3answers
115 views

Pythagorean triplet adding up to 1000

Project Euler problem 9 says: A Pythagorean triplet is a set of three natural numbers, \$a < b < c\$, for which, $$a^2 + b^2 = c^2$$ For example, \$3^2 + 4^2 = 9 + 16 = 25 = 5^2\$. ...
3
votes
2answers
71 views

Print list item in a rectangular frame

The aim is to have that list ["Hello", "World", "in", "a", "frame"] And make it printed like below ...
1
vote
1answer
56 views

Grouping the results in an array having same name

results is a list of dict having panel name and work type and price to do that work on that panel. There can be two dicts for same name and work type where one of ...
2
votes
1answer
47 views

HackerRank - The Grid Search

Was playing around tonight and thought this problem was interesting enough to post here. Given a 2D array of digits, try to find the location of a given 2D pattern of digits. Input Format ...
3
votes
4answers
48 views

Beginning guessing game in Python

I've just finished work on my guessing game. I'm still fairly new to Python, so I'm looking for feedback and criticism on the code. ...
2
votes
1answer
32 views

Read output from a subprocess executed by Python

I've written these 2 methods and I'm wondering if the 2nd method, which uses yield is more efficient or if I'm using yield wrong. Can someone refactor the 2nd method to make it more efficient for ...
3
votes
0answers
60 views

Poker Hands in Python

Project Euler problem 54 asks: The file, poker.txt, contains one-thousand random hands dealt to two players. Each line of the file contains ten cards (separated by a single space): the first five ...