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

learn more… | top users | synonyms

-2
votes
1answer
24 views

Transferring list from function to function in Python [on hold]

This code is supposed to take the list from one function to the other. The list will only come with one element. I am a beginner in Python and need some help. The code works, but only brings one ...
2
votes
2answers
24 views

Basic value comparisons

I made a value comparison "programming language" similar to a previous one I made, except this one is based solely on value comparisons. ...
3
votes
2answers
28 views

Making this Python state machine more pythonic

Is there a replacement for the global? My goal is to have something really simple with as small an amount of code as possible. The real code is used to parse a text file of nested structures. ...
1
vote
0answers
26 views

Python script for making a table

I have written a Python 2.6.6 script in order to make tables by taking the third column of every text file in a particular subgroup (signal and background in this case[particle physics]). However, I ...
-2
votes
0answers
8 views

Python MySQLdb not refreshing database information [on hold]

I'm currently codiing a simple IRC moderator/utility bot. I plan to have a web interface that will easily update command data and whether or not the command is enable using a MySQL database to store ...
-2
votes
0answers
15 views

Python Code Correction [on hold]

def f(x): x = x + 1 print 'x =', x return x x = 3 z = f(x) print 'z =', z print 'x =', x Hi. I'm a noob at programming and started to learn in Python. A ...
7
votes
5answers
362 views

Python code for detecting a single item moved in a list

I need to write a function that takes an original list of unique values and a resulting list: [0,1,2,3] [0,3,1,2] and detect that only a single element was ...
2
votes
1answer
22 views

Are 2 Django URLs pointing at 1 view unorthodox?

I'm in the process of writing a private messaging system and I have 2 URLs which go to the same view (is that bad?). The logic behind this madness relates to the way user relationships are structured ...
2
votes
1answer
43 views

A function to convert FASTA .txt to a dictionary

I'd like feedback on my function to convert FASTA data to a dictionary in Python. Here's an example of FASTA text: ...
2
votes
2answers
125 views

HackerRank “Manasa and Stones” in Python

Problem Statement: Manasa is out on a hike with friends. She finds a trail of stones with numbers on them. She starts following the trail and notices that two consecutive stones have a difference ...
5
votes
2answers
290 views

HackerRank “Service Lane” in Python

Problem statement: Calvin is driving his favorite vehicle on the 101 freeway. He notices that the check engine light of his vehicle is on, and he wants to service it immediately to avoid any ...
1
vote
1answer
30 views

Django project structure and settings configuration

I'm new to Django but after some googling and reading blogs I found that I should follow this kind of structure (I compiled 2-3 suggested structure and this is what I came with): ...
6
votes
1answer
68 views

Topological Sort and Graphing in Python 3

I wrote a program for DFS traversal, topological sort, find all vertices, and has_cycle methods. Can you please suggest more elegant and eloquent ways for this program? (Perhaps better ways to ...
4
votes
1answer
35 views

Thin proxy class for hashables

I need some kind of thin wrapper object to mark dictionary keys, like: d = { Required('name'): str, Optional('age'): int, } And these wrappers should behave ...
5
votes
3answers
99 views

Convert dict entries to sets and lists

Can you please tell me if there is a better way to do this? ...
-4
votes
0answers
24 views

Merge Sort Implementation in Python unorderable types [on hold]

This merge sort implementation fails on this error: " if (left_list[0] <= right_list[0]): TypeError: unorderable types: int() <= list()." I know what the error means but I don't understand why ...
5
votes
1answer
56 views

Increase the speed of this Caesar Cipher

Here's my attempt at a Caesar Cipher encoder/decoder. If given a key, it will encrypt the given string. However, if you do not specify a key, it checks each of the 26 possible keys and returns the ...
2
votes
2answers
94 views

Project Euler 81 (minimum path sum through a matrix)

Problem Statement: In the 5 by 5 matrix below, 131 673 234 103 18 201 96 342 965 150 630 803 746 422 111 537 699 497 121 956 805 732 524 37 331 ...
-2
votes
0answers
19 views

Challenge to convert a simple IDL code into Python [on hold]

Asking if someone can help me to convert the following IDL code into python: ...
3
votes
1answer
36 views

How to better indent multiline strings with many string formatting args?

I have a function, that is used in flask, for logging application errors: ...
1
vote
2answers
129 views

Grouping string to list of strings

The following is function that I have written to group a string to groups, based on whether there's consecutive repeated occurrence. Fop example AAAABBBBAAB is ...
2
votes
2answers
55 views

Mutual friends finder written in Python

I've written a server/client tool which can "check the Six degrees of separation theory" in Russian social network VK.com. Client sends task (which contains two VK IDs) and Server tries to find all ...
5
votes
1answer
87 views

Groupby in NumPy

To avoid the XY problem, here is an example of what I need. Given the sorted integer input array [1 1 1 2 2 3], I would like to produce the following slices, ...
1
vote
1answer
56 views

Getting rid of certain HTML tags

This code simply returns a small section of HTML code and then gets rid of all tags except for break tags. It seems inefficient because you cannot search and replace with a beautiful soup object as ...
0
votes
0answers
15 views

Changing the NumPy array into the required shape [closed]

I have a 2D NumPy array of 480 rows and 1440 columns as named by data below: The first element belongs to (49.875S,179.875W), the second element belongs to ...
4
votes
4answers
65 views

Refactoring huge if..elif in __init__ how?

I have this huge __init__ method, which is readable I think, but still doesn't feel right after watching Clean Coders videos (content of Clean Code book by Robert ...
4
votes
1answer
35 views

Stable partition in Numpy

In essence, I need to do a stable partition: All elements of the 1D np.array a that are present in ...
8
votes
2answers
302 views

Scrape an HTML table with python

I think I'm on the right track, but ANY suggestions or critques are welcome. The program just scrapes an HTML table and prints it to stdout. ...
6
votes
1answer
69 views

Agnostic means of identifying a member

I'm attempting to provide an agnostic means of identifying a member. I need a nickname, a guid, and one of ...
-3
votes
0answers
13 views

Sumifs Function for Panda Based on Two Criteria (Python 3.4) [closed]

I am trying to implement something similar to an excel based sumifs function based on two criteria that will add up two rows. So the input will look like this ...
7
votes
1answer
107 views

Optimizing “Poker hands” challenge solution

I'm trying to solve the project Euler problem 54. In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the following way: High Card: Highest ...
5
votes
3answers
146 views

Project Euler #9 - Pythagorean triplets

This code works, and I'm trying to figure out if there's a better way to optimize it. As you can see, I've cut down drastically on time just by using numbers that work for ...
6
votes
1answer
105 views
+50

Light Python pubsub lib, but is it too light?

In attempting to decouple the object from the messaging I came up with the following short code for adding publish-subscribe functionality to a Python script. ...
4
votes
3answers
74 views

Validate parameters within a range

Function to use several blocks of if:elif:else: that all take slightly different conditional statements. I'm trying to format integers into a 2 digit string, ...
10
votes
1answer
647 views

Battle a random enemy

I am trying to write a text adventure as my first Python project. For this segment, I wanted a random enemy (part of a class with its own attributes) to appear and then enter a turn based battle with ...
8
votes
6answers
854 views

Is it possible to optimize the following boolean checks?

The following code works and it prints out only True as it is supposed to, for all the different cases: ...
0
votes
0answers
20 views

Neighbours from point connections

I am working with a mesh of points (in 3d, although I doubt it makes a difference). The mesh is given as list of lists, each list containing the three vertices of a triangle in said mesh: for ...
3
votes
1answer
33 views

CLI Command Search Tool - XML Framework

I'm working on the OSCP, and Information Security certificate based around penetration testing. CLI-based tools seem to be the core of most pen-testing assignments, so I'd like to build a tool aiding ...
2
votes
0answers
28 views

Parallelizing some model fitting code using multiprocessing

I'm trying to refactor some code for fitting parametric models that are defined symbolically using Theano. My goal is for all models to expose a common interface so that, as far as possible, they can ...
-4
votes
1answer
55 views

How to shorten Python Code [closed]

How to shorten the following line of code in Python if((post["datatype"][index]=="VARCHAR2" or post["datatype"][index]=="NUMBER")):
4
votes
2answers
78 views

Readable way to print a list of things in Python

I am trying to solve the common "print a character after every item in a list, except the last one" problem. I do not want to use list indices. There are a couple of simple ways to do this in Python, ...
2
votes
1answer
47 views

How can I make this implementation of Euler's method more efficient?

I have an implementation of an Euler method for solving N-many 1st order coupled differential equations, but I feel that I did not write it as efficiently as I could, due to lack of programming ...
14
votes
2answers
679 views

Avoiding Python multiline string indentation

I want to make this code: ...
3
votes
2answers
92 views

Group and send all files to filetype folder

I have around ~2M of files in one folder, which I need to manage. So, I want to separate them in groups by their filetypes. Example: filenames ...
0
votes
1answer
31 views

Checking for variable being passed in Python [closed]

I have a Python script which is littered with if statements which checks for whether a variable was passed. An example is some function like this: ...
5
votes
2answers
39 views

Map reduce tester ported from bash to Python

My MapReduce tester is clearly ported from Shell, short of args=None for line in args or read_input(), what's a better way of ...
3
votes
1answer
24 views

Merging values with lists as flat-lists

I'm merging dictionaries together in series. Each one may/may not have lists as values. I'd like to merge indefinitely and, have the final merged dictionary contain only flat lists as values. Any ...
6
votes
3answers
68 views

WSGI static file handler

I put up a simple WSGI static file handler, but I'm skeptical about its efficiency, also because I got a handful of errors while benchmarking it with Apache Benchmark. The errors are: ...
0
votes
0answers
38 views

Speeding up filtering function in Pandas

I have a CSV file with 400 000 rows and the following headers: ...
6
votes
2answers
179 views

Simple Python/Bash interaction

I use at to schedule jobs and atq to display the scheduled jobs. But it mildly irritates me in that I have to look up each job ...