Tagged Questions
2
votes
4answers
83 views
Python: Make this code more compact?
How can I get rid of the excessive repetition in this code?
Code: http://pastebin.com/13e2nWM9
The program calculates equations of motion (SUVAT Equations) based on data provided by the user.
The ...
1
vote
1answer
53 views
What's the most pythonic way to build this dictionary?
I want to create a dictionary such that letters in the first row of a QWERTY keyboard are given a value of one, keys in the home row are given a value of zero, and keys in the bottom row are given a ...
1
vote
1answer
39 views
better way to match text and replace
Consider this, I have File1:
SNP_ID GENE_ID # Header not present in original file
rs1 TRIML1,TRIML2
rs2 D4S234E
rs4 ACCN5,CTSO
rs5 ODZ3
rs6 TRIML1
and File2:
SNP1_ID SNP2_ID DRUG # Header not ...
0
votes
1answer
86 views
efficient way to compare elements between very long lists
I have two lists in files:
File 1 has 200000 rows and looks like
MAP2K4 FLNC
MYPN ACTN2
ACVR1 FNTA
UGT2A1 HPGDS
RPA2 STAT3
ARF1 GGA3
ARF3 ARFIP2
ARF3 ARFIP1
AKR1A1 EXOSC4
RPA2 ...
1
vote
4answers
345 views
counting duplicate words in python the fastest way
I was trying to count duplicate words over a list of 230 thousand words.I used python dictionary to do so. The code is given below:
for words in word_list:
if words in word_dict.keys():
...
0
votes
2answers
136 views
Python conversion calculator loop / code efficiency
The following is the (semi) finished version of a simple Mils to Degrees conversion calculator I built in Python 2.7 as a learning exercise. I am new to Python and still working out the kinks. The ...
2
votes
4answers
99 views
python efficiency Which is better for setting variables being used in the context of constants
Solution:
Python computes the value of the variable when set, and the variable is merely a pointer. I would say the first option is better for clarity, since the only difference in runtime is how long ...
0
votes
1answer
69 views
Scraping tables and writing rows to CSV
I'm working on a project that scrapes about 400,000 records in tables of 20 records each. Currently my script creates a complete list of URLs for the pages, and then for each URL it opens the page, ...
1
vote
3answers
285 views
Python combinations of 2 lists
What is the pythonic way to calculated all the product combinations of two lists. So given two lists of length n I'd liked to return a list of length 2^n containing the products.
Like ...
3
votes
2answers
132 views
First items in inner list efficiently as possible
I have a coordinated storage list in python A[row,col,value] for storing non-zeros values.
How can I get the list of all the row indexes? I expected this A[0:][0] to work as print A[0:] prints the ...
0
votes
3answers
87 views
What is the most efficient way to dynamically create class instances?
I don't know how many class instances I will have from the get-go, so I need to create them dynamically, but I would also like to keep the code tidy and readable.
I was thinking of doing something ...
1
vote
4answers
299 views
How efficient is this Python Code for the fibonacci sequence?
I wrote this a few days ago and it seems to be working fine, but it is slow. It took 25 seconds to generate the 1 millionth number in the fibonacci sequence. Is there a way to make this more ...
1
vote
1answer
60 views
which is better practice for python in this case ?iterator inside function or outside function
If i mention the word 'state machine' , most people would go for state machine design. So i'd like to simplify the case to focus on the point.
Suggested here is a text flow, it's very long or it's ...
0
votes
3answers
88 views
The efficiency of “in” and “for” operations in python
I got two lists here, called A and B.
len(A) > len(B)
There are two ways to do something:
Method one:
def f():
return [someFunc(i) for i in A if i in B]
Method two:
def f():
return ...
0
votes
1answer
180 views
Reverse AND inverse python3.x OrderedDict efficiently
After many attempts to create one-liners that will invert key-value pairs, and reverse an OrderedDict, I have this:
from collections import OrderedDict as OD
attributes=OD((('brand','asus'), ...