57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 1 day 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.
Aargh. :-) There are many weird things here, but I'll concentrate on just one.
any and all can accept a generator. So drop the []s (replace them with () in lines 20 and 21). And of course, lines 10 and 14 can be much easier written with map.
More
Use enumerate instead of range(len(. And use sum instead of len([... if ...]). See my solution. ;-)
More
Clear? Hm. :-D
That while loop is really unfortunate. You could have used for for what you need, and if you really like the potential infinity, since you've already imported itertools, count would be nice. ;-)
BTW, "chain(*starmap(chain" is really Rambo-like construct. :-DD
More
Very clear. :-P
_0 would be nice addition. :-D
BTW, sum([[a for b] for c], []), isn't it just [a for c for b]?
[a[cipher[0]][cipher[1]] for cipher in m], use unpacking: [a[i][j] for i,j in m].
More
"word in text.lower()" is much nicer than that regex monstrosity. :-]
More
If this was an attempt to write the most complicated solution, you've nearly done it. :-O
May I just ask what those [0:] slices you thought were doing? Because the answer is: nothing.
all(mark == 'X' for mark in game_result[0]) is simply game_result[0] == 'XXX'.
And == can be chained (lines 32, 3
More
Since you've already broken the 80col boundary...
if cond1:
if cond2:
return True
return False
is simply "return cond1 and cond2". ;-)
Also, any(char.isdigit() for char in data) can be said any(map(str.isdigit, data)).
Then cond2 can be said all(any(map(f, data)) for
More
You have a weird definition of clear. ;-) Iterating over a genexp with for is really strange (when you can transform your item in the loop itself). At least write it as map(str.isalpha, words.split()).
Also, in line 4 you can just multiply count + 1 by is_word. ;-)
More
Please use // instead of int(/). Or better yet, see divmod builtin.
Also, tail recursion is not really Pythonic... looping is better. This would fail for number with more than 100 digits.
More
Aaargh. My eyes hurt. :-P
First, this is a classic example of how to go overboard with names. It would be _more readable_ if game_result was named just `r`. :-P
And those comments should really be names.
m_diag = r[0][0] + r[1][1] + r[2][2]
Or even
m_diag = ''.join(row[i] for i, row in
More
Sorry, but doesn't. mapping lambdas doesn't make sense when you have genexps:
all(map(lambda x: cond, seq)) ~~~> all(cond for x in seq)
Simpler, shorter, more elegant, and faster.
Also,
from string import ascii_lowercase as alp
But you already know that probably. :-)
More
Don't use int for truncation, it's bad style (Guido tries to deprecate such usage). When floordividing, use the dedicated operator: `n // 2`.
Even better: since you need both // and %, why not acquire both at once:
half, odd = divmod(len(data), 2)
if odd:
return sum(data[half-1:hal
More
This is a 9 line solution. :-) It can be considered 2 line solution if you want. :-)
More
Your meat is smelly. :-P
Lambda mapped over zip, put into a list, and then that list converted to a tuple, to be added to another tuple and named a one-letter name, to be used in a simple tail-recursion.
I don't even know where to start.
Eta reduction:
lambda x: max(x) ~~~> max
lam
More
While you're importing, you can
from operator import mul
and use that as the first argument to reduce. :-)
Also, if you're using reduce, you can go old school all the way and use map and filter too, instead of that ultramodern list comprehension. :-D
More
`any(... for ...)` is better than `any([... for ...])`. Among other things, it shortcircuits the evaluation as soon as it finds a true value. List comprehension always constructs the whole list.
More
Hm, a nice generalization of [my code](https://checkio.org/mission/comp_funcs/publications/veky/python-3/def-def-def/?ordering=most_voted). :-D
More