27
Eduardo Tsen
Last seen 1 year ago
Member for 2 years, 13 days
Difficulty Normal
For the record, math.gcd(*integers) changed in version 3.9:
> Added support for an arbitrary number of arguments. Formerly, only two arguments were supported.
More
Please note, that _combinations(x,1)_ just wraps the elements of x in one-tuples. Instead, why not use the elements directly?
for i in x:
s = [i * x for x in segment2]
Hint: _math_ module implements function [dist(p,q)](https://docs.python.org/3/library/math.html#math.dist)
More
You can use _a.splitlines()_ instead of _a.split('\n')_.
And I would use an _if_ clause insteand of _try/expect_ here.
More
Instead of strptime(), fromisotime() could have been used.
To get rid of the leading zero, use "%-I".
Wasn't aware of the capital "%P" as I only found the locale dependent lowercased "%p".
More
if text.lower().count(i.lower())
can be replaced by (note that i already is lower() by precondition):
if i in text.lower()
Leaving out the brackets as _sum_ can work with the generator directly, moving the condition to the front, as _sum_ works fine with bools, this will lead to what seems
More
I would try to avoid calling a (possibly expensive - depending on input) operation two times per iteration here:
pos = 0
loc = 0
while x.find('X',pos) != -1:
loc = x.find('X',pos)
res1 += s[loc]
pos = loc+1
You could rearrange your loop:
More
I think the key point of this mission is to use [property/@property](https://docs.python.org/3/library/functions.html#property) to handle _is_alive_ implicitly and not as explicit state.
More
Hm, using search funcions as key, doesn't this lead to O(n**2)? Here twice?
More
I like the
zip(els[::2], els[1::2])])
in comparison to my
zip(*(iter(els),)*2)
More
Instead of
set([... for ... in ...])
use set comprehension directly
{... for ... in ...}
More
Instead of list-comprehension and then transformation to set, use set-comprehension directly:
final_result = {i for i in text.lower() if i in alphabet}
More
In your implementation, all operations are calculated for each function call. You could enhance it, by using lamda expressions in your map (and possibly move the map definition outside of the function).
More
Ah, you could have replaced "m" => ".m." to save one call.
More
Refering to your _equip_weapon_ method, instead of:
no_minus if no_minus > 0 else 0
you always can use:
max(0, no_minus)
That said, you could save some typing, by using hasattr/getattr/setattr (change your _weapon.power_heal_ to _weapon.heal_power_ first):
for key in ("health","a
More
Should this:
return ''.join(set(trio))
not be:
return check
as the variable is already defined?
More
Very clean implementation of the abstract factory pattern, following the textbook, even though I'm always tempted to push functunality up the hierarchy, like implementing _introduce()_ only once and passing up the format string in the super constructor call.
More