Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.
1
vote
0answers
3 views
Identifying equivalent lists
Title:
Identifying equivalent lists
I am using lists as keys, and therefore want to identify equivalent ones.
For example,
[0, 2, 2, 1, 1, 2]
[4, 0, 0, 1, 1, 0]
are 'equivalent' in my book. I ...
0
votes
0answers
11 views
MySQLdb Python prevent duplicate insert [migrated]
I wrote this python script to import a specific xls file into mysql. It works fine but if it's run twice on the same data it will create duplicate entries. I'm pretty sure I need to use MySQL JOIN but ...
3
votes
1answer
43 views
Optimization of average calculation
I have a list of dictionaries, with keys 'a', 'n', 'o', 'u'.
Is there a way to speed up this calculation, for instance with NumPy? There are tens of thousands of items in the list.
The data is drawn ...
3
votes
1answer
39 views
Python Optimizing/Speeding up the retrieval of values in a large string
I have a string containing around 1 million sets of float/int coords, i.e.:
'5.06433685685, 0.32574574576, 2.3467345584, 1,,,'
They are all in one large string and only the first 3 values are ...
4
votes
1answer
30 views
Sparse Bitarray Class in Python (or rather frequently having contiguous elements with the same value)
Sparse is probably the wrong word - this is for encoding arrays of booleans where contiguous values tend to be the same. It'd be great to know a proper name for this data structure so I could read ...
0
votes
1answer
181 views
Python code. Not returning any value [closed]
Its a beginner program that involves playing (rock, paper, scissors, lizard, spock)
Is my code correct? There aren't any syntax errors on IDLE but I cant seem to get it to work.
Any ideas. I'm new to ...
3
votes
1answer
59 views
Using Python to model a single elimination tournament
I'm learning python and I want to model a single elimination tournament like they use in athletic events like tennis, basketball, etc. The idea would be to insert some meaningful metrics to determine ...
1
vote
1answer
38 views
Python / Numpy running 15x slower than MATLAB - am I using Numpy effeciently?
Here is some code I wrote in Python / Numpy that I pretty much directly translated from MATLAB code. When I run the code in MATLAB on my machine, it takes roughly 17 seconds. When I run the code in ...
7
votes
1answer
84 views
Python __new__ and __init__ usage
I'm trying to write a Python module to handle matrices. (I know about numpy, this is just for fun)
So far I have written a few classes, Matrix, Dim, and Vec. Matrix and Vec are both subclasses of ...
3
votes
1answer
89 views
Need an algorithm to optimize grouping python dictionaries in hierarchical form
Previously I asked a question on how to group dictionaries in a list in a hierarchical structure.
Initially I wanted to group a list of dictionaries that looks like the following, using multiple ...
4
votes
3answers
250 views
Code review for python password generator
The following code is a simple random password generator that spits out a randomized password based on some input flags.
import string
import random
import argparse
def gen_char(lower, upper, digit, ...
2
votes
2answers
50 views
Want to sharpen my Python / Regex skills
I have a relatively simple project to parse some http server logs using Python and SQLite. I wrote up the code but I'm always looking for tips on being a better Python scripter. Though this is a ...
0
votes
1answer
45 views
Reverse a linked list [closed]
Problem: create a linked list and reverse the list appending with '<-'.
Example, if the linked list is [1,2,3,4,5,6], so the result is 5 <- 4 <- 3 <- 2 <- 1.
Here is the code
class ...
0
votes
4answers
35 views
How to optimise the code and make a function to make it reusable?
The following code I made have 3 parts, which are very similar to each other, but my programming level is very limited, I can make a function to make a concise code that archive the same result:
if ...
2
votes
0answers
40 views
Iterator and Generator version of python range function
I have created iterator and generator version of python range function
Here is Generator version:
def irange(*args):
if len(args) > 3:
raise TypeError('irange() expected at most 3 ...