13
Kristoffel Pirard
Last seen 4 years ago
Member for 9 years, 9 months, 23 days
Difficulty Normal
Why the slices? `x[0][0:1]` can be perfectly written as `x[0][0]`, since we're dealing with strings here.
The artificial 'not' should probably be replaced by simply `None`, and then you also get rid of the trailing `!= 'not'`.
A syntactic sugar used by many is the condensed equality form:
More
This is the first solution I see that sticks to the task and returns integers. Although 0 and 1 will coerce to False and True, of course, which would make it shorter :)
More
Linear search through the if-statements can easily be replaced by a dict of functions.
And returning True and False just obfuscates the meaning of the code: simply returning a predicate should do.
More
Indexing the given OPERATOR_NAMES just ties your code tightly to the order the operators are defined in. Tight coupling should be avoided at all cost - at least in a program where maintainability is an issue.
Also: the | operator is a 'bitwise or', not your old 'logical or' (cfr https://wiki.pyt
More
After reformatting (no runtime cost :)
return
sum(
sum( ((0,) + l) [col:col + 3] )
for l in (((0,),) + grid)[row:row + 3])
- grid[row][col]
Great find to just subtract `grid[r][c]` in the end!
What is the use for `((0, ) + l)` as opposed to just `
More
Coming from C, this is a very clear solution.
The vast number of conditions, nested loops and `continue` statements makes it hard to relate to the problem statement. Python offers [generator expressions](https://wiki.python.org/moin/Generators) to simplify this greatly. You should give them a t
More
very clear, expressing the `neighbors` as a plain tuple! Alignment can make these coordinates visible at a glance:
[-1, -1], [-1, 0], [-1, 1],
[ 0, -1], [ 0, 1],
[ 1, -1], [ 1, 0], [ 1, 1]
It takes some time to understand the `tempx, tempy` expression - as dedicated and clear
More
You know that `x.__contains__(y)` can be (and should be) written as `y in x`?
More
Quite clear solution.
Checking for the second letter is an unneeded twist; you're lucky there is no 'ROTATE' command.
The `else` branch in your loop is unneeded, too, though it makes the program more robust, analogous to the ability to POP from an empty stack.
In order to keep a larger interpret
More
Style remark: variable names tend to start with lower case in Python code.
`queue[len(queue) - 1]` can be written as `queue[-1]`
`Answer += 0`... why? Your can lose clutter by reversing the condition:
if queue:
answer += queue[-1]
`print(answer)`: is that a debugging left-over?
More