57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 22 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.
Using not with 2 branches is usually frowned upon. It's better to reverse branches and eliminate not:
if array:
return sum ...
return 0
Even better is to use try. But you're probably too young for that. :-)
More
"if int(digit)" is enough.
Or better, to remove duplications of int(...):
for digit in map(int, str(number)):
if digit:
mal *= digit
(You can even use filter(None,...) but let's not go there.:)
BTW what's "mal" (as a name)?
More
Same as before:
if args:
return max ...
return 0
In new Pythons, you can use default=0 in min and max.
More
Nice "oneliner". :-P But why all those list(...)s? [] are enough.
And sum([a,b,a]) is really nicer written as 2*a+b.
More
Why a list?? You never do anything with it except append 1, increment some element (pointless) and return len.
More
Aaargh. Don't ever loop over indices when you can loop over values.
for char in number:
More
You have some really weird ways of thinking. Why outer loop is nice, and inner one is ugly? :-P
for i in w:
for j in w:
More
About that horrible line 17, I think I have good news for you: tuple comparisons.
(a, b) < (c, d) <~~~> a < c or a == c and b < d
You can also learn about key argument to min and max.
More
First, a + a + a is really a*3, even when a is a str.
Now you know that, remove the duplication. :-]
More
"lambda i: abs(i)" has a much nicer name. It has three letters. ;-)
Google eta-reduction if you want to know more. ;-)
More
Wow, heavy artillery. :-D Even I didn't know about operator.indexOf. Really cool. :-)
More
This is not C (nor Perl), you don't need parens after while, if, ...
base += -c if isfib(c) else 1
"c = 0 # counter" is a really weird comment. If you want to call it counter, do so. You can even have two names: counter = c = 0. :-D
Calling "fib" a function that _checks_ whether somethi
More
Nice homework: now remove _all_ the duplication from that code above. ;-P
And don't write empty except.
And why float(...), and int(round..., and all. these. parentheses. ??
More
When c is of len 1 (as it is here), "c in ['(', '{', '[']" is the same as "c in '({['".
Also, that line 7 could really use some dict instead of treating data like the code.
"len(l) == 0" is simply "not l".
More