57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 6 hours ago
Member for 11 years, 7 months, 3 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.
Nice BFSolution. :-) Here are a few suggestions:
list.pop(0) performance is much weaker than it needs to be (linear
complexity). For a queue, it's much better to use a collections.deque, and
.popleft from it. If you don't want to import collections, and your queue
isn't using a huge amout of poplef
More
This is a standard, and I hope intended, solution for this task. However,
it's interesting to know that Python has a tool for specializing functions
directly: functools.partial. So you don't have to define a new function,
you just construct a partial object from sorted on key=abs, and name it
checki
More
A nice idea, but could be written much more directly. Check [this one](https://py.checkio.org/mission/three-words/publications/hrvoje/python-27/slightly-weird-solution/?ordering=most_voted&filtering=all) for example. :-)
More
Python is not Java. Not every API should be a single method of an ad hoc
class. distance could be just a function. And calling it as
distance(point1, point2) is more in line with commutativity than
point1.distance(point2). (Not quite related, but useful hint: use
math.hypot.)
Alternatively, Python
More
elif can be handy. :-) And instead of keeping it all in a str, it's better to keep it in a list, `' '.join`ing it at the end.
More
Too many indices! :-o But this is minor.
Real problem is using 10 and 100 as magic numbers. Besides being
maintainability hell (network expands, and in some random moment in the
future, your code gives wrong results silently), documentation is lacking.
Comments do help at the moment of assignm
More
Don't modify the list while iterating through it! It could spawn weird bugs.
https://unspecified.wordpress.com/2009/02/12/thou-shalt-not-modify-a-list-during-iteration/
If you want a queue, use a `collections.deque`.
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
It's ok, but if you use cmath, you'll see that there are no different cases. :-)
Also, why name something `r` (an empty name, probably for "value to **r**eturn") just to return it immediately afterwards. Especially at the end... just
return [round(func(a, c), 2) for func in (v, sa)]
But of co
More
There are many weird things in your code, but I'll ask just this: why are you stringifying your keys? `si` returns a tuple of floats, which is perfectly usable as a key.
More
It is a standard backtracking approach, with labyrinth used as a
scratchbook for algorithm state. The main thing that could be improved is
the ugly repetition of code. A for loop over a dictionary mapping
directions to offsets would be much nicer. And the extra benefit would be
that the comments
More
Standard string concatenation approach. For longer messages, you should be
aware of the "Schlemiel the painter" danger (you construct new strings
again and again, longer each time), but for short messages (in this task,
len is at most 1000) it's ok.
More
https://www.youtube.com/watch?v=o9pEzgHorH0
There is really no reason for a class here.
More
1. Revolver can be derived from collections.deque with maxlen=6, thus giving you loading logic for free.
2. Those triple-quoted strings are an abomination. Use textwrap.dedent, or just use "\n" like a normal person. :-)
3. A bug: chew_cigar doesn't reduce the number of cigars.
4. Those enemies co
More
`for spam in map(xform, eggs)` is almost always an antipattern. You're packaging one iteration into an expression, just to evolve it in a suite right afterwards. Since you already have a suite, `map` gives you no ROI. :-)
for word in words.split():
if word.isalpha():
...
More
Nice. Reminds me of definition by cases. :-) Of course, in LaTeX you would have `\\` instead of single `\`. :-D
More