57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 1 day 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.
Lines 11~15: aaaargh. _Please_ tell me you know how to do this in a sane way. :-P
More
Nice function names. :-)
Please learn about str and list multiplication. Much easier to write _and_ to read than [blah for i? in range(...)].
And you might want to learn that str class has some really nice methods. .ljust, for example. ;-)
More
If you want queue, use collections.deque. list.pop(0) in a loop is really blowing your complexity.
More
You'd probably scream if I told you you don't need line 3. :-D Or at least you'd scream when you understand _why_. ;-]]
More
"Meh" is probably because of code duplication. Try to eliminate it, it's fun. :-D
-(a-b-c) should be (b+c-a).
"for iterblah: if cond:" is probably easier written as "if any(cond for iterblah):" (or even, in this case, use "if max(map(abs, coss))>=1"
map(lambda var: transf, seqblah) is reall
More
First, lines 6~7 can be written as "safe += left in pawns or right in pawns".
After you do that, you see that the whole function is just a simple sum. So you can solve it with sum builtin.
Also, "pawns" is a set. So the condition can be simplified as {left, right} & pawns (as bool).
Lines 4
More
You already imported collections... please import deque from there too, don't write queue.pop(0).
Also, did you really need a separate (global) function getGraph? It seems to me that you just split your check\_connection in 2 parts, and arbitrarily named and extracted first one, leaving the secon
More
Funny usage of bisect. :-)
Again you with "if len(blah) == 0: continue"... just say "if blah:" (and indent lines 8~10).
blahset |= {item}... I really find blahset.add(item) easier to read. And Python does, too. ;-)
Of course, the best solution would be "yield" - that is, neighbours is natur
More
Yeah, annoying. :-P Too many irregularities and convolutions.
It's time to learn about str.maketrans. ;-)
''.join([...]) - drop the brackets. Your code will be nicer, more readable, and faster.
for i, z in ... and then using z[0], z[1]: you can unpack directly. for i, (d, j) in ...
Also,
More
Argh. I'm stabbed by complexity! :-P
Anyway, what do you think line 6 does? (Hint: it doesn't copy a list). ;-)
Also, please learn about while...else and similar constructs. That l is really ugly.
More
Whenever you employ enumerate just to use the index to iterate through another sequence, what you should really use is zip.
tmin = min(t for a, t in zip(attacked, times) if a)
Also, \\-continuation is kinda pointless when you break the 80col barrier totally anyway. :-P
Title is cool, but LISP
More
Wasn't it easier to give additional parameter than have inc and dec as separate functions? :-)
Also, don't join([...for...]). Drop the brackets.
More
OK. Lines 8~9 could have been nested under line 5, but this is good.
More
That outer "{}|{}".format really should have been "|".join.
Also, lambda x: x.upper() is just unbound: str.upper. Same, you could have re.compiled striped, then lambda in line 12 could also be eliminated: striped.match.
Nice usage of keyword parameters. ;-)
More
"striped" is a bit negatively written. A bit of positive thinking could help. ;-)
Also, \\ is not really needed at end of line 14.
More
You don't need lines 16 and 28.
Nice usage of generators.
Line 4: x = y = 1.
Isn't it simpler to yield 1 only once, then yield y instead of x+y in the loop?
Instead of that clumsy take, wasn't it easier to provide an argument to generate_fibonacci?
More
A\*a\*a\*rgh. :-D
Until now, I thought you were coming from LISP. Now Java smell is really too strong in the above code. :-O
More
Cool. But you really could have used what you imported from math, instead of that while. ;-P
More