27
Last seen 3 months ago
Member for 10 years, 4 months, 9 days
Difficulty Normal
>>> False == 0
True
>>> True == 1
True
so line№16 looks excessive
More
if len(data) % 2 is 0:
No!
First, the results of this "is" comparison with with "calculated objects" are undefined (depends on compiler).
On Cpython it works, because it keeps **some small integers** in pull, but this is a derty hack.
The only legal and recommended "reserved" argument for "is"
More
What about divmod:
for integer, numeral in MAP:
count, n = divmod(n, integer)
r.append(numeral * count)
return ''.join(r)
More
def area(self):
north = self.south + self.width_NS
east = self.west + self.width_WE
return (north - self.south) * (east - self.west)
a bit confusing ;)
More
... explicit is better than implicit ...
It's a Hell:
self.connections = set()
for con in connections:
self.add(con)
How to relate self and self.connections?
I urge python's guru.
More
# line №5:
grid = list(map(list, crossword))
# lines №№133..138:
return tuple(map(''.join, grid))
# It's a python ;)
More
((1,2),(2,1))[row%2][col%2]
Too heavy for my mind
(rown + coln) % 2 + 1
:=))
More
Every python's object returns True or False, if you ask ;)
For numbers - zero returns False, for list or dict (etc) empty returns False
ie
x = 777
if x: # True
pass
More
What about style?
lines 15..16 - chain assignment:
p = r = 0
lines 17, 19, 39 - redundant brackets:
while p < lm:
lines 23, 24, 25, 26, 43, 45 - increment:
p += tmp
And, of course:
def f(r, c):
return (r + c) % 2 + 1
One more advice: http://pep8online.com/
More
gun = tuple(
tuple(map(int, s)) for s in
('000000000000000000000000100000000000',
'000000000000000000000010100000000000',
'000000000000110000001100000000000011',
'000000000001000100001100000000000011',
'110000000010000010001100000000000000',
'11000000001000101100
More
To chase the reflection - perfect.
Final checks sometimes fails:
while True:
assert checker(hunt, ('.....X..',
'.X.XXX..',
'....X...',
'.X.XXX..',
'..X..X..',
More
... functions and method calls are expensive (more so than in C or Java) ... /by Guido/
More
Bubble seems a good idea, but really not: the same number of comparisons (as most common algo) plus useless swaps.
A bit about codestyle:
list2=[]
for i in sequence:
list2.append(i)
# shorter:
list2 = list(sequence)
...
for i in r
More
elif i == "POP" and len(A): sum+=A.pop()
elif len(A): sum+= A[-1]
Add a bit of elegance:
else:
if A:
sum += A.pop() if i == "POP" else A[-1]
and name var as a "sum" is a bad practice :(
More