57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 23 hours ago
Member for 11 years, 6 months, 7 days
Difficulty Advanced
We shall not cease from exploration, and the end of all our exploring will be to arrive where we started and know the place for the first time.
Horrible. :-P
First, why those empty lines? They don't increase readability, especially since one of lines is too long.
sum([... for ...]) ~~~> sum(... for ...)
Just drop the []. Generator expressions are nicer, clearer, faster, and use less memory.
And you surely don't need list compr
More
Nice algo. A few Pythonic nitpickings:
* It would be nicer if tuples in q were (time, pos,...), then you could just sort them directly by time. Or if you want to be explicit, you could have used namedtuple.
* q.pop(0) is slow with no good reason to use it. It would be better to q.sort(reverse=True
More
It always bugged me why people import the wrong thing from collections. :-) Counter is obviously more specific, and precisely what you need.
And don't map literal lambdas, especially of one variable. You get precisely nothing.
sum(map(lambda arg: expr, seq)) ~~~> sum(expr for arg in seq)
More
Not fancy or efficient, I agree. Simple to understand... well.
Horrible duplications, indexing instead of unpacking and naming things, superfluous constructs, unnecessary rebindings... and to top it all off,
if adict.get(key, False):
:-O Even Py2 should have `key in adict` construct by now.
More
Inspired by [bukebuer](http://www.checkio.org/mission/network-loops/publications/bukebuer/python-27/second/?ordering=most_voted) (and Guido;).
More
`a = max(a, incredibly_long_name, key=len)` is cool, but every time incredibly_long_name doesn't give something longer than a, Python "rebinds" a to itself. Maybe it would be better after all to use if?
b = incredibly_long_name
if len(b) > len(a): a = b
More
But you should use it fully FTW. :-P Check out unicodedata.category and unicodedata.combining. ;-)
More
I'd still like to register my general dislike of eval, but here it's overweighted by elegance of this solution. Congratulations, you win one of Veky's fives! :-)
And yes, I find it funny that you call it golf, and then use spaces as is proper. :-) As if you're saying, "this is _so_ short, I can spr
More
words.split() would probably be better.
Also, spaces. num += 1 and num = 0 are really much clearer, especially since you wrote it that way in line 2.
More
As I told you, look at [bunnychai](http://www.checkio.org/mission/how-much-gold/publications/bunnychai/python-27/first/?ordering=most_voted). ;-)
More
You see, generators aren't so hard. :-)
Though, you don't need i. You can use _, or simply range(len(a)).
More
Real overdose. In what way is `bool(i<0)` better than just `i<0`? Do you also write `float(3.5)` or `list([2,8])`?
Also, eval takes another argument, you don't need to replace. :-)
More
Missing/nonmissing spaces make this code ugly at a first sight. "curage" is probably misnamed, should be "current_opacity", right?
Also, your fib generator is too complicated. Use tuple assignment for great good. :-)
def fibgen():
a, b = 0, 1
while b < 5e3:
a, b = b
More
Your code has a weird mix of using //2, /2 and /2.0. (That's probably the consequence of using Py2.:) Either stay with Py2 (without `from __future__ import division`), use `/2` and `/2.0`, or (much better;) switch to Py3, where you use `//2` and `/2`.
Also, length should be properly spelled. Or jus
More