57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 13 hours ago
Member for 11 years, 6 months, 12 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.
You don't need those backslashes (except the last one, unless you add
another pair of parentheses), and you can indent the
subconditions accordingly to their grouping/priority.
More
I put those chars @StefanPochmann generously provided me to good use - traded them for spaces at a favorable exchange rate. :-D
[Of course, now someone will make a 'vfn' solution without spaces. But that's just too predictable.:]
More
I didn't think I'd ever post an [NSFW link](https://xkcd.com/853/) to CiO, but there's a first time for everything. :-D
More
Yes, you should use string.translate. But you should use [all of its capabilities](https://py.checkio.org/mission/caesar-cipher-decryptor/publications/veky/python-3/punctuation-as-junk/?ordering=most_voted&filtering=all), not fall back to regex for such a simple thing as deleting extraneous characte
More
Again, sum is a builtin: sum(array[::2]) is what you need.
Also, you don't need len(p) inside p[]: array[-1] is ok.
Space after :, but not before :.
Nice EAFP way. ;-)
More
`self` is a weird name in this context. :-)
That duplication of code for rows and cols... wouldn't it be much nicer to write a function?
for i_row in around(row, len(grid)):
for i_col in around(col, len(grid[i_row])):
yield grid[i_row][i_col]
In fact, by using slice instea
More
`ele` is a weird abbrevi. :-) They usually don't end with a vowel.
Making a new list (via comprehension) would probably be easier than modifying the argument. And if you really wanted to iterate through a copy, saying `.copy()` is probably clearer than `[:]`.
More
hash? Ah, I should have known it. You came here from the Kingdom of Perl. Noone else would check for substring using regex. :-D
That being said, study collections.Counter and don't invent the wheel all over again. :-)
Line 14: m = max(count_dict, key=count_dict.get)
keys.sort(), then return keys[
More
I took the liberty of rewriting your code in True Python:
def CC(DL):
"""Rings connected with least-connected ring"""
res1 = {i1: sum(i1 in i2 for i2 in DL) for i in DL for i1 in i}
res2 = {i for i, v in res1.items() if v == min(res1.values())}
return {t for i in
More
Of course, sys.maxunicode would be much more clear, if only CiO weren't so paranoid. :-P
More
inside is just `max(divmod(top-1, 4)) < 4 - length`. And set([spam for egggs]) is `{spam for eggs}`.
And if you return a set(sides) from square, you can just use subset operator (`square <= lines`) in the last line.
More
Why the exception at all? If the text contains no English letters, it's obvious that "a" satisfies all conditions for the return value. ;-P Relevant quote from Zen:
Special cases aren't special enough to break the rules.
Don't invent counter strategy from scratch (well, from dict:). Instead im
More
This one is the most similar to mine, I guess. But still a bit more complicated. :-)
More
Line 4 doesn't serve any purpose, you know? :-) In fact, you can just return the expressions from lines 6 and 8 directly. But it's nice to name at least the return value, when the function name is totally uninformative. ;-)
"!= 0" can be removed from line 5. Read it as "if there is a remainder".
I
More
Not bad. Handling singular cases is cool. :-)
You might want to use some of Python's batteries, though. For example,
for a, b, c in itertools.permutations(eval(data)):
with contextlib.suppress(ZeroDivisionError):
... lines 7 ~ 12
... lines 17 & 18
seems much ni
More
Bravo! I thought about how to use that wonderfully weird API with endswith(tuple), but didn't figure it out. Of course, .pop before and manual loop was the solution.
BTW you don't need "list" in line 2.
More