57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 21 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.
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
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
Cool usage of sum of slice, but please use // instead of math.floor and division.
More
Last line is much nicer written as return not stack.
You can avoid None contortions by having a sentinel value at the bottom of stack, see my solution. ;-)
(Or at least you can write "if not stack or char != closed[stack.pop()]:".)
I don't really get why are you filtering brackets as a separate s
More
You can avoid global res if you use nonlocal (remove lines 1 and 3, and change line 6 to "nonlocal res"). You can avoid even that if you pass [res] as a parameter (with a default value). Otherwise, yes, list of map is a standard for loop replacement (only you get a pile of Nones in the process, whic
More
str(int(field) - 1) can also be replaced by chr(ord(field) - 1). Then that code can be extracted as a separate function. :-)
More
In this case, str has a method that's much nicer to use than .split. It's .partition. You get your parts as separate variables, being empty if nonexistent.
instr, _, arg = command.partition(" ")
Then you just use instr and arg instead of parts[0] and parts[1]. Much more readable.
Also, please
More
If you know about max with key, you can really solve this task in a much more direct way.
max(string.ascii_letters, key=text.lower().count)
"import collections" is probably a relic from using Counter. Remove it. :-)
More
Oh, please don't. :-) Fastest in C is not fastest in Python.
Please read [this discussion](http://www.checkio.org/mission/hamming-distance2/publications/veky/python-3/publication/).
More