57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 23 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.
Ok, this is ridiculous. Usually I don't mind some complexity blowup, but
n^4 pushes it. And why str(i) each time?
More
Don't iterate over indices when you can iterate over the list itself.
for element in array[0:len(array):2]:
sum += element
BTW do you really need elif? Can len(array) be less than zero? :-) And while we're at it, a is already 0 in the empty case, you don't need to set it again. :-]
More
Nice. Reminds me of definition by cases. :-) Of course, in LaTeX you would have `\\` instead of single `\`. :-D
More
`for spam in map(xform, eggs)` is almost always an antipattern. You're packaging one iteration into an expression, just to evolve it in a suite right afterwards. Since you already have a suite, `map` gives you no ROI. :-)
for word in words.split():
if word.isalpha():
...
More
Many things can be summed, at least conceptually. Look at this: remove `replace_map`, and the transformation in line 8 (`board=game_result`), and replace all `sum`s with `''.join`s (or put `sum=''.join` at the start:).
Then, instead of checking for `3` and `-3`, you can check for `XXX` and `OOO`. M
More
You really like that `True if condition else False` idiom? `condition` does the same thing.
Also, see `any` builtin.
More
Nice and surprisingly readable. With all those actions, you're only missing some kind of Journal in your architecture. :-P
More
Now you have two _languages_ that clash. Using % formatting could actually help readability here. ;-)
More
20 is a magical constant. Much better would be to use `itertools.takewhile`.
And x is _really_ slow. In fact it is used by some people as a trivial benchmark. :-) (Most famous example is probably [this one](https://www.youtube.com/watch?v=MCs5OvhV9S4).;)
More
Yes, there is: Don't use regexen. :-D
More
Don't you think your code could use some refactoring? :-)
Also, everytime you write
if condition: return True
else: return False
a little python dies. :-P
More
Aaargh. Semantically empty names (`newList`, seriously??), the code is _drowned_ in the sea of comments (those things are connected: if you chose more semantical names, you wouldn't need comments!), and most importantly, you're doing iteration wrong.
for index in range(0, len(sequence)): ~~~
More
Ah, a butchering of a nice algorithm. :-P
def checkio(data):
arabic = dict(I=1, V=5, X=10, L=50, C=100, D=500, M=1000)
roman = dict(zip(arabic.values(), arabic))
def fragments():
for exponent, digit in enumerate(map(int, reversed(str(data)))):
More
This is not "as efficient as possible", but you already know that. :-)
It is also not as concise as it could be. Look at [this beauty](https://py.checkio.org/mission/the-longest-palindromic/publications/veky/python-3/although-straightforwardness-beats-speed/). :-)
And yes, comments are not really
More
No, they [aren't](https://py.checkio.org/mission/break-rings/publications/DiZ/python-3/cycle/?ordering=most_voted&filtering=all). :-P
`frozenset((u,v))` looks like an identity crisis. Isn't `frozenset({u,v})` better? :-)
And you again with your negated set operations. :-P
if not set1 - set2:
More
OMG. filtering a lambda, then listing it, only to iterate through it. Hard to believe this wasn't intentionally ugly. :-P
How about
for b, w, n in states:
if n == n0:
(Indenting 2 spaces is acceptable in such situations, if you're stingy with line lengths.)
---
states[(b, w, n)]
More