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.
I could suppress the StopIteration near the end, but decided this was enough. :-D
More
Nice, but misses a few tricks.
For instance, (-1)**i is much shorter than what you wrote after ::. :-P
More
Line 9 surely shows some misunderstanding of how Python works. What did you think it does (as opposed to just "return data_new")?
And of course, you can just write a list comprehension.
return [x for x in data if cnt[x] > 1]
More
Ok, but that prints are cluttering your code. It's ok for debugging, but remove them before publishing.
More
This is just one example of how PEP 479 is bad for Python. Another one is at https://py.checkio.org/mission/merge-intervals/publications/veky/python-3/generator/#comment-54572.
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
... not. :-P
list(map(blah.__getitem__, days))
[blah[day] for day in days]
compare.
---
BTW do you write (2 * 5) + 3 ? Then don't do the same with Boolean multiplication and addition. :-P
More
Every time you map a lambda, a python dies. :-P
map(lambda variable: whatever, sequence) ~~~> [whatever for variable in sequence]
More
The title, of course, refers to two different ways of string formatting in Python. They are introduced in lines 4 and 9, and they "live together in perfect harmony" in line 11. :-)
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
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
An interesting question: why are parentheses needed?
A more interesting question: were they needed in all previous versions of Python? ;-)
More
It can be factored much more. :-) See [mine](https://py.checkio.org/mission/seven-segment/publications/veky/python-3/spec-lit-broken/). ;-]
More
Very inovative, but surely not clear. And it's not that you actually gain
anything: since you have to calculate and compare distances for two
neighboring items, you could just calculate and compare them for all items.
You'd have a linear algorithmic instead of linearithmic sorting one. :-9
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
LOL. Yes, sort might be unnecessary, but doing it twice... :-o And it even isn't one line. :-P
More