22
Matthias
Last seen 2 years ago
Member for 8 years, 11 months, 28 days
Difficulty Normal
Since you filed your solution as "Clean":
- You could use more expressive variable names, e.g. `lines` instead of `a`, `max_length` instead of `l`, etc.
- Instead of initializing and incrementing a counter in lines 5 and 9 you could use a common python idiom `enumerate`: `for i, x in enumerate(x):`
More
- You could replace the magic number ``4`` with ``calendar.FRIDAY``.
- Instead of constructing a list and then using its length you could use ``sum()``.
More
Your comment sounds like one of the key points of [Structured Programming](https://en.wikipedia.org/wiki/Structured_programming).
But I've read about this from other experts who advise against following the _single return statement_ policy too religiously. One of the most prominent ones is Steven M
More
Donald E. Knuth, one of the most famous computer scientists, wrote that *the bubble sort seems to have nothing to recommend it, except a catchy name and the fact that it leads to some interesting theoretical problems*. Please consider using Python's builtin functions ``list.sort()`` and ``sorted()``
More
* ``set.add()`` and ``set.discard()`` always return ``None``, so ``return not ...`` saves you an additional ``return True`` but is slightly confusing.
* ``Friends.connected(self, name)`` does contain ``name`` even if ``{name, name}`` is in ``self.connections``.
More
FYI: Python 3 dropped support for the *cmp* keyword argument. You might consider using the optional keyword argument *key*, which is also much more efficient.
More
FYI: You are working on a very low level. You might want to consider using `datetime.datetime` and `datetime.timedelta` objects, which allow time arithmetic and have methods like `strptime` and `strftime`.
More
FYI: You could replace the two operations on line 4 with ``ldiv, lmod = divmod(l, 2)``.
More
Since you filed this under "clear": Don't you think linke 5 would be clearer as ``return int(bitcom, 2) == pattern``?
More
FYI: Instead of three `for`-loops you can use `itertools.combinations(cakes, 3)`.
More
FYI: Instead of `float("{0:.2f}".format(vol))` you could write `round(vol, 2)`.
More
If you want to keep it as short as possible you could write ``sum(a)`` instead of ``a[0]+a[1]``.
More
Since you filed your solution under "clear":
You could avoid some repetition by rewriting ``go``:
```
def go(p, q):
moves = (
(-1, -2), (-1, +2), (+1, -2), (+1, +2),
(-2, -1), (-2, +1), (+2, -1), (+2, +1))
for dp, dq in moves:
new_pos = (p + dp, q + dq)
if al
More