57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 23 hours ago
Member for 11 years, 6 months, 24 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 like those complicated control flows very much, do you? :-D
You're one of rare people here that can stuff if/if/else, nested if, not, or, continue and return from for loop in about 6 PEP8-approved lines. :-D
More
Any particular reason why you use "if n != 0" instead of "if n"?
BTW that "words" really could be a generator function. "yield whatever" is nicer than "words.append(whatever)".
More
"i = s = 1" is probably nicer than separate assignments.
number - s >= 0 is just "number >= s".
Lines 8, 9, 10, 11 and 15 (:-o) can be written as one line: "return max(number, s - i)".
More
When you already write that list comprehension in line 6, instead of 0 you can just write data[j][i]. And solution over. :-P
BTW, "something == 0 or something >= 10" can be written more easily as
not 0 < something < 10
More
See Counter in collections module.
Lines 23 and 25 are just: return alphaf == alphas.
Your code is really too parallel. You should consider writing a function and then applying it to first_word and second_word separately.
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
Wouldn't it be nicer if lambdas were declared with real number of parameters, and called with *args? If you insist on indexing, "lambda x:" really should be factored out.
More
Line 1 expression can just be "secs // 60 + (secs % 60 > 0)". bool _is_ int. ;-)
That antipattern in lines 10~13 really should have been using collections.Counter. Learn about it, you'll love it. ;-)
Lines 16~19 are _precisely_ the reason why Guido finally added conditional expressions to Pyth
More
When a loop has 4 lines, one of which is "continue", that's surely an overkill. :-)
"if word != w and word.endswith(w):" is obvious solution. "for w in dic - {word}:" is a clever one. ;-)
More
Wow. Until now, I thought you came from Perl land, but now I'm not so sure. Very few of these people know about accumulator recursions. :-)
More
NEVER write empty except. It catches much more than you think. Here it doesn't really matter much, but don't pick that habit. Always state what you intend to catch.
More
Aargh. Don't write C# in Python. And _please_ don't use pseudoHungarian notation. It completely misses the point of Python.
Also, learn Python idioms. Many of your lines can be written in a clearer, sometimes even point-free way. In some cases you don't even need to learn new idioms, just use them
More
Why didn't you just put s=0 in line 1, then you don't need line 2 at all?
Also, len() is unnecessary. Sequences are boolable.
More