57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 15 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.
Lines 2, 3 and 4 can be written at once:
tlist = list(filter(str.isalpha, text.lower()))
or if you don't like unbound methods,
tlist = [x for x in text.lower() if x.isalpha()]
Line 5: please avoid semicolon if in any way possible. "show, counter = 0, []". BTW why "counter" name f
More
May I ask why importing two modules, when simple builtin sum would have sufficed?
Yes, solution is surely cute. But IMO it would have been cuter with m=sum(matrix,[]).
More
Why do you have a variable is_safe? Every time you set it, you just return it immediately. You can have "return False" instead of lines 9~10, and
return upper_case_count and lower_case_count and digit_count
instead of lines 21~24.
More
That purple "max" variable is trying to tell you something. Don't write max from scratch, use max builtin. It has a key argument.
Also, lines 4~7 are a bit repetitive. Learn about collections.Counter, it will make your life easier. ;-)
More
This is an original reducer. :-)
Since you use Fraction and reduce only once, it would probably be clearer to "import fractions, functools" at the top, and then address them with full names.
About that "[1] +"... you might want to know that functools.reduce accepts optional third parameter for
More
avoidable(p, q) = all(map(int.__ne__, index(p), index(q)))
Many people don't know map can take more than 2 arguments. :-) Also,
for spam in (blah for eggs in ham):
yoord
is really nicer written as:
for eggs in ham:
spam = blah
yoord
Also, you can
More
Line 18 is wrong. rounded gamma is _not_ necessarily equal to 180 - rounded alpha - rounded beta.
BTW why do you reinvent the wheel (in this case, builtin round function)?
More
namedtuple('complex', 'real imag') is better, it supports more operations. ;-)
More
Line 17 is really pointless. :-)
You don't need zip inside map. map(sum, p, dp) is ok.
Start of line 23 can be written: np in m.keys() - visited. Not very useful here, but good to know: keys is a set-like object.
More
ROTFL.
But it would be way more cool if you mapped OPERATION_NAMES to symbols from "∧∨→⊕≡" instead of relying on indexes. This is not maintainable. ;-P
More
What's bad and what's surprise here? (except CiO Python finally supports yield from:).
I consider isinstance(x, list) a bit nicer than type(x) == list. And it will work for subclasses of list too. ;-)
More
Nice usage of conditional expression. However, it would be much nicer if you explicitly checked n in range(len(array)), or at least 0<=n< len(array). I know of preconditions, but it's not much harder to write those additional conditions explicitly.
More
Now when people ask me how dimpleqonx works, I'll just point them to your code. Thanks. :-D
More
Here is your code, halved:
import itertools, operator
def trim(lists):
if lists:
first, *rest = lists
for t in [first] + [first[::-1]]*(first[0]!=first[1]):
for remains in trim(rest): yield [t] + remains
else: yield []
def sqgen
More