New answers tagged

7 votes

Algorithm "sort except zero"

I would suggest you use NumPy for anything that manipulates collections of numbers of the same type. A NumPy array is a more efficient container than a list in this case, an the package contain a ...
Cris Luengo's user avatar
  • 5,010
7 votes

Algorithm "sort except zero"

301_Moved_Permanently's answer is great and changes the performance from \$O(nk\log(n))\$ to \$O(n\log(n))\$. The change results in a measurable impact on performance. To satiate both my curiosity and ...
Peilonrayz's user avatar
  • 42.4k
12 votes
Accepted

Algorithm "sort except zero"

Most of the work will be done by your call to sorted. You just need to make sure to not make too much extra fluff around that call. One particular call that may ...
301_Moved_Permanently's user avatar
2 votes

CPU emulator written in python (Adjustable Microcode!)

This is a von Neumann machine, which is risky. It introduces the possibility of a whole category of bugs that by definition cannot exist on a Harvard machine. If you're able, rewrite to represent the ...
Reinderien's user avatar
  • 58.1k
2 votes
Accepted

NumPy script to convert BGR to HSL and back

I find the code easy to read; there are no legibility issues (within the context that you need to understand Numpy). It's a good idea that you're doing division safety checks, but you should simplify ...
Reinderien's user avatar
  • 58.1k
1 vote

Application install code- Need to remove Nested Loops and make code more compact and readable. Code installs application and its version as per req

I think more sentiments to support the advice by @J_H would be : Nesting if statements You may like statement nesting If you are a beginner just like me, But after ...
KhodeNima's user avatar
2 votes

NumPy script to convert BGR to HSL and back

Floating-point arithmetic is very slow and since you're doing a lot of it, it plays a major part in slowing things down. Since you're dealing with colours, you can replace floats with ints in the ...
QuasiStellar's user avatar
  • 2,089
1 vote

2D Point subclass of complex builtin

You want to learn about metaclasses. That's good! You also want to develop a geometry tool following best practices - that's also good! Where this immediately falls apart is Pure Python is expressly ...
Reinderien's user avatar
  • 58.1k
2 votes
Accepted

2D Point subclass of complex builtin

doctests Kudos for the doctests, they are very helpful. Doctests are documentation I can believe! They do not bit rot (since failing tests are quickly noticed). ...
J_H's user avatar
  • 13.8k
6 votes

Generate random password from a list of allowed characters

Security The biggest red flag that I see is using random to generate passwords. This is warned against in the python docs on random. Warning: The pseudo-random ...
ToAskOrNotToAsk's user avatar
4 votes

Generate random password from a list of allowed characters

What you have posted is not complete since it is missing definitions and will not execute as is. What is this function supposed to do? The title of your post explains in slight detail what the ...
Booboo's user avatar
  • 704
3 votes
Accepted

Metaclass Wrapping Builtin to Enforce Subclass Type

shebang #!/usr/bin/env python The shebang looks beautiful, thank you. Everyone should implement like this. Very portable, and it obeys ...
J_H's user avatar
  • 13.8k
1 vote

Application install code- Need to remove Nested Loops and make code more compact and readable. Code installs application and its version as per req

You voiced several concerns: Need to remove Nested Loops and make code more compact and readable. I don't know what (1) is all about, since I only counted a single ...
J_H's user avatar
  • 13.8k

Top 50 recent answers are included