57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 2 hours ago
Member for 11 years, 6 months, 7 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.
"myNum"? That's, like, a subexpression name that facilitates understanding of code? :-p
Also, isn't number already an int?
More
Cool. You might wish to know that setA & setB is a nicer way to write .intersection().
Also, why not just call them A and B? Please don't use Hungarian notation in Python, it doesn't really make sense.
More
You can chain comparisons.
if number % 3 == number % 5 == 0:
Nice to know but not really needed: you can use not % without parentheses (as opposed to C).
if not number % 3:
More
Ok, now try to be honest. _What_ do you think these continues do? They don't speed up the code, that's for sure. :-)
BTW ever heard of elif?
More
Suggestions? Of course. Factor out the duplication into a separate function.
And then make it one line if you want. ;-)
More
What you really need is += datetime.timedelta(1).
But since you already use fromordinal and toordinal, wasn't it easier to iterate through the ordinals instead of dates?
And a nitpick: what do you think line 1 is doing? (This is a frequent misconception in Python... it's completely unnecessary. Yo
More
Nice, but one big error.
If angA and angB are rounded, the third angle (rounded) is not necessarily 180 - angA - angB (in degrees). For example, 59.6, 59.7, 60.7.
More
"if len(myStack) > 0" is just "if myStack".
Lines 23&24: see list.pop. You will be delighted. ;-)
What do you think lines 18~20 and 25~27 are doing?? :-o
Those comments are at best unnecessary, and at worst wrong. Don't repeat yourself, especially if you're doing this in two languages: Python and
More
About that rjusts... see str.zfill. Much nicer and more explicit to work with.
That i at the end... please learn to use enumerate. Much easier to avoid one-off errors, and more readable. Also, use list comprehensions instead of writing back something entirely different to the same place.
Also, why
More
Not really original. :-)
Also, you might want to read on eta-reduction. checkio=sum, for example. :-)
More
Why + ".*"? Really no reason for that.
And of course, "in" works perfectly fine with str. No need to import heavy machinery of re.
More
Cool. But don't you think there's an easier way to do what you do in lines 16~18?
Also, condition in line 12 is more usually written as "if not shortages".
More
This is beginning to look a lot like Python, to paraphrase that old Christmas song. :-D
The only jarring thing is that name in line 2. Just inline it, man.
for word in words.split():
More
ROTFL.
P.S. Even I'd never be so bold to import * from operator. :-D But you handle it excellently. :-)
More
You don't need nonlocal. buffer doesn't have to be nonlocal at all (since you don't rebind it), and ptr can be just an argument.
def BF(s):
buffer = ... # how about defaultdict(int)? Much cleaner.
def execute(s, ptr=0):
...
... ret += execute(s[i+1:],
More
Those two if-elses are unnecessary. If you really wanted to handle the case of empty data (despite the precondition), you could have done it like this:
if length % 2: ... #handle the odd case
elif data: ... #handle the even case
elif is useful, empty list can be sorted trivially, and pytho
More
Lines 13~16 (and maybe others;) can be replaced with just one. Builtin max is your friend. ;-)
More