57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 16 hours ago
Member for 11 years, 6 months, 6 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.
Nice and clear. Of course, Py2.7 is complicated with having to be forced to
float division, but still, 12. and 60. in the divisor might be better than
H = float(H) and M = float(M). Also, H %= 12 is a nicer way to write that
if.
More
Lines 10, 11, 12 and 13 are just
return max(wheat, pigeons)
Also, I know you know about +=, since you use it in line 8. Use it also in line 14 (and use -= in line 7).
Thirdly, condition 0 > a - (b + c) is really weirdly written. It's really just a < b + c.
Fourthly, lines 3 and 4 can
More
You might wish to study str.zfill and dict.get methods. But especially the first one. ;-)
u, t, h, T = str(data).zfill(4)
You can even "map(int," over them, but that might be too advanced. :-)
More
Yes, that's better. :-) Though you still accomplish precisely nothing by rebinding data locally just before you return it. ;-]
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
You don't need to have so many special cases, det of 0x0 matrix being 1 is enough.
Also, p in lines 17~18 is just (-1) ** i.
More
Funny, this is exactly the same length:
safe_pawns=lambda p:sum(bool({chr(ord(c)+o)+chr(ord(r)-1)for o in(-1,1)}&p)for c,r in p)
More
Very high level code. Exact, documented, with references. I like it.
BTW line 28 made me laugh. Avoiding code duplication at every price. :-D
More
First, really too many cases.
Second, "if blah != 0" and "if blah > 0"... could really be just "if blah".
Third, use divmod. It will be _much_ simpler than what you're doing (lines 20~21, lines 48~49,...).
More
Lines 4~6: `islower = isupper = isnumeric = False`
Lines 16~19: `return isnumeric and isupper and islower`. In fact you can just add `and len(data) >= 10` and eliminate lines 8, 20 and 21.
More
That's an ok solution. However, it would be much nicer (faster, shorter, less memory, more readable, more Pythonic) to use generator expression instead of list comprehension. Just drop the brackets []. ;-)
More
You're writing docstrings on the wrong side. :-P
Also, that action at a distance via changing retlist is much more naturally written using a generator.
More
You were very close with that "key". ;-)
return max(sorted(map), key=map.count)
Also, you don't need re. You can just use "abcdefghijklmnopqrstuvwxyz" (also known as string.ascii_lowercase) as first argument to max, and key=text.count as second. But then it's too easy. :-D
More
Decorate-Sort-Undecorate is sooo last century. :-P
The most ironic is that you _do_ use key. :-D
More
Well, what would you expect? FILE_NOT_FOUND? :-D
(https://thedailywtf.com/articles/What_Is_Truth_0x3f_)
More
Nice. Of course, can be expressed with any.
any(word.endswith(suffix) for suffix in words_set for word in words_set - {suffix})
Or itertools.permutations, if you're in the mood. :-)
More