11
Last seen 3 years ago
Member for 9 years, 1 month, 28 days
Difficulty Normal
Very nice. I used a dictionary, but I can see the benefit of a presorted list here.
More
Your __while__ condition and the __return__ on line 16 are redundant. If __number__ happens to be less or equal to 0, line 6 catches that. And since there is no __break__ anywhere, line 16 is unreachable code.
More
Nice demonstration of a generator. Even though I have never used one, your code is very clear and understandable. Maybe I wouldn't have used the arrival metaphor, because the old ones _don't_ arrive, they are there already. ;)
But that's about all I have to criticize.
More
Line 6: __range(len(names_of_rel))__ would be more flexible, in case someone decided to put multi-level connections in __network__. ;)
Lines 7 through 11: You use __names_of_rel[i]__ _four times_ and __names_of_rel[1-i]__ twice. Those are list operations, which cost time, but the values don't chang
More
Your RE is a bit repetitious.
if re.search(r'([a-z]+\s){2}[a-z]+', words, re.IGNORECASE):
is shorter and somewhat clearer in my opinion.
Anyway, I don't like throwing REs at everything, when there are simpler means available. **str.isalpha()** is a built-in method, so no need to **import re**.
More
How do you not get headaches when writing something like this? I get them just from _reading_ it. ;)
More
If I have to scroll horizontally to read it, it is not clear. -1 for bad style.
The approach I like. I used the same.
More
Reading your comments I was somehow reminded of [The Zen of Python](http://www.thezenofpython.com/):
> Readability counts.
>
> If the implementation is hard to explain, it's a bad idea.
Sorry.
But why not simply go through the pawn one at a time calculate where another pawn must be to protect it
More
Your checks on lines 5 and 9 are pointless. You do member checking against **pawns** one lines 13 and 15. So, if you happen to check an illegal position, meaning it is outside the board, it will be a miss anyway.
Also, if have to do such checks, < and > are better options in my opinion. One keystrok
More
Could have saved yourself the -97. It's all relative, literally. ;)
And **pawns** is already a set, which you basically make a copy of.
More
Your comments are misleading:
> returns **row number** for pawn p as **"c3"** (first row is 0)
And you have five, repeat five, functions? And all are oneliners.
Anyway, **is_safe()** checks against all pawns on the board, which you must account for in line 13. Also, the task was to check if a pawn
More
A little complicated. Plus, you don't need **string**. You can use ord() to get the ASCII number of a character and chr() reverses that.
You also potentially check _all_ other _pawns'_ positions, but you only need to check _two_ positions and see if there is a pawn on it. And we were given a set, w
More
Lol, I also had the idea to use a dictionary and enumeration. But somehow it didn't cross my mind to just use enumerate directly, so I put it in a dict comprehension. Silly me. ;)
Oh, the use of recursion is nice too. At one point I thought about it and then dismissed it after failing to find the r
More
**int()** is redundant for a division of integers. Also, it is basically the same as
number//other_number
More
Nice approach. But it took me a while to grasp what's happening. I'd say that makes it a little less clear. ;)
Oh, and line 19 should be the other way around:
if state[0] != '.' and len(set(state)) == 1: # no point for set() if [0] is '.'
But that's just a minor thing.
More
Finally I see someone with the same idea of zipping the list. ;)
I just found out that reversed(zip(*game_result)) is a 90 degree left rotation of the matrix. That makes the check of the diagonals a breeze. Have a look:
http://www.checkio.org/mission/x-o-referee/publications/Peter.White/python-27/
More
I like the nested list comprehension. Also nice use of enumeration. Lines 4 and 5 are repetitious, though, but pragmatic I guess.
More
Nice. But the last line I don't like all that much. There is a variable in there, the player. The two **ifs** are basically the same only different players.
More
Oh dear! There is not a single iteration in there. I hope your fingers hurt after typing that. ;)
More