57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 13 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.
I think [this one](http://www.checkio.org/mission/digits-multiplication/publications/blabaster/python-3/golf/?ordering=most_voted) will floor you. :-D
Also, // (and divmod) might be nice to learn.
while number:
number, digit = divmod(number, 10)
if digit: product *= digit
More
What you did in first two cases, you can do in others, too.
elif operation == 'implication': return not (x == 1 and y == 0)
elif operation == 'exclusive': return x + y == 1
elif operation == 'equivalence': return x == y
Those OPERATION_NAMES repeating are not giving you anything. Much
More
Best compared to what? :-) You can have just one expression,
','.join(phrases).replace('right', 'left')
And then you can just stick
left_join = lambda phrases:
at the beginning. :-)
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
Wow, what a cheat! :-D
Of course it doesn't always work, but still very nice.
Instead of (second) str, you can use id. It is false in rarer occasions. ;-]
More
def checkio(from_date, to_date):
"""Count Saturdays and Sundays between dates."""
weeks, days = divmod((to_date - from_date).days, 7)
nd = from_date.weekday() + days # next same weekday as to_date
return 2*weeks + (nd > 4) + (days and nd > 5)
Same algo, 4 times
More
[since CiO will probably never get back links to commenter's solutions :-(, [here is the link to mine](http://www.checkio.org/mission/mind-switcher/publications/veky/python-3/zendoh/?ordering=most_voted), for comparison. This is a reply to ignalion's comment on my code.]
While you might think our s
More
Using one-letter names is not really clear in most cases. Especially if those letters don't naturally denote these objects: `n` is ok, but what's `b`?
Also, you can just return whatever you want directly instead of naming it and returning via name.
More
Please don't semicolon.
You have Py3, use it. Use // for int halving instead of heavy math.
No () after keywords: `if len(data) % 2:`
Consider using if-else expressions instead of doubling return.
More
1. What do you think line 4 is doing? (Answer: nothing useful.;)
2. Please use //. It is available in Py2 too.
3. instead of float(blah)/2, you can use blah/2.0
4. lengteArray is _longer_ than len(data). What did you intend to accomplish using it?
5. You can just return whatever you need, no rea
More
You can chain comparisons.
... if 'A' <= c <= 'Z'
Though, of course, it's even simpler to use a method.
... if c.isupper()
More
See `collections.Counter` instead of reinventing it. ;-)
Also, that horrible line 5. How much time did it take for you to write it?
if item not in ' -!@#$%^&*(){}[]|":?><,./;+=~0123456789':
And you still forgot `'`, right?
Much simpler:
if item.isalpha():
More
Argh. This is just bad. Typos, Py2/Py3 confusion, misuse of sorted, a pointless "helping" function, superfluous print... sorry. No cookie for you. And definitely not clear.
def checkio(lista):
lista.sort()
half, odd = divmod(len(lista), 2)
return lista[half] if odd else
More
... how many were going to [St. Ives](http://en.wikipedia.org/wiki/As_I_was_going_to_St_Ives#Lyrics)? :-D
More
Naive is one problem. Unpythonic is much bigger problem here. ;-)
Powerset is trying to be much more general (it's even global, as opposed to other aux functions:) and it is really unneeded here. First, if "iterable" _really_ was iterable, you wouldn't need line 6 (if it was _iterator_, then you'd
More
That's better. :-) But...
`names` could benefit from set union. Concretely, `set().union(*self.collections)` is what you need. :-)
Of course, then `connected` is just `names` on another collection of `Friends`.
And when you have instances with just one piece of data, it makes sense to inherit. Py
More