57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 1 day ago
Member for 11 years, 6 months, 7 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.
Again, much duplication of code.
for limits in '09 az AZ'.split():
if not re.search('-'.join(limits), data):
return False
(You can even use `all` with a generator expression.)
More
But why?
>>> 5 .bit_length()
3
And hey, one shift is better than two. :-)
(second & (1 << col)) >> col ~~~> (second >> col) & 1
More
Lines 4,5,6:
digits = lowers = uppers = 0
Line 1: unnecessary. :-)
Lines 8~13:
digits += c.isdigit()
lowers += c.islower()
uppers += c.isupper()
or if you insist on using unbound method, remove initialization and just say
digits = sum(map(str.isdigit, data))
Lines 15~18:
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
First, if you use ord for the first one, you can use it for the second one too. And then you have a nicer way to do it:
ax, ay = a.encode()
bx, by = b.encode()
Also, you can exploit symmetry more in that return, saying that one of those differences is signed, while other is unsigned.
More
The whole point of // is that you can ignore the remainder. So you don't need -1 in line 5. :-)
And then you see that you use l//2 three times, so it's nice to name it beforehand. (Which is BTW a reason why you named that len a very short name. **Important lesson**: whenever you use a one-letter na
More
That triply nested ifs are a bit more complicated than needed. Lines 13 and 14 shouldn't check conditions in that order. Alternatively, lines 15 and 16 should use "elif".
Also, " ".join might be useful to know.
More
"len(stack) != 0" is more simply written as just "stack" inside conditionals. Sequences can bool. :-)
More
Too many "list"s (in cols).
You don't need () around '\_\_\_' in lines.
You don't need 0 and 9 (len) in slices: inline[::4].
If you're really obsessed with speed, try inlining diags and cols. Also try extending rows directly instead of copying.
More
`set` has a much more versatile API than just "make null, add, and count elements". :-) Also, it's very nice to use `string` for `punctuation`, but whitelisting is more useful than blacklisting. See my solution.
More
Line 27 can be
del braille_out[-1]
Also in line 19, you should learn about str.ljust method. It's useful. ;-)
In line 10 you don't need a dict: .update(zip(... is ok.
Height and width of a Braille character are not likely to change. You seem to me like person defining
M = 12 # number o
More
A few stylistic remarks, and a big problem:
* a-b>0 is much clearer written as a>b (you use it 5 times, and inconsistently)
* [building[0],building[2],building[4]] can be written as a slice: building[::2]
* you can just say: numberBuildings+=visible at the end, bools know how to count.
* The
More
That's how I planned to call my solution, bit there might be children around. 😛
More
Wow. One of these rare tasks where list actually _is_ the right data structure. ;-D
More
Eta-reduction applies here: checkio = \_\_builtins\_\_['s''um']. And as you see, + is not needed. ;-)
More