57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 15 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.
First, at the start, you need or.
if len(data) < 10 or data == data.lower() or data == data.upper():
return False
Or even better...
... or data in {data.lower(), data.upper()}:
You don't need line 11. list is iterating through your str the same way for would do.
for item in
More
:-) If you're going to use `len() and`, you can use it in at least two other missions. Try to find them. ;-]
More
> Python is cool :)
You have no idea. :-D
First, you don't have to write your uppercase. Just
from string import ascii_uppercase
Also, that if can be much better placed _after_ for. Then you don't need singular else.
''.join(ch for ch in text if ch in ascii_uppercase)
And of course, th
More
... if array ... is much better than ... if len(array). If you really want to use len(array), you can use and. :-)
len(array) and sum(...)*...
More
Yup, that's the one. If elements of r are only pairs, it's simplest.
Though it seems not the shortest. ;-)
break_rings=lambda r:min(map(len,map(set,__import__("itertools").product(*r))))
More
Nice, but "flag" is a bit technical. Wouldn't it be nicer as:
has_upper = has_lower = has_digit = False
And you don't need `()` about `len(data) >= 10`. Python has sensible precedence rules, mostly. :-]
More
What's bad and what's surprise here? (except CiO Python finally supports yield from:).
I consider isinstance(x, list) a bit nicer than type(x) == list. And it will work for subclasses of list too. ;-)
More
Nice. BTW squeezed-space operators like ** and even > can be ok, but after the colon there should really be a space.
(Unless you're golfing, but in that case you can save a lot more chars - even spaces.:)
More
First, don't map lambda, use genexps:
tuple(map(lambda x: number%x == 0, [3,5])) ~~~> tuple(not number%x for x in [3,5])
(Also, as you see, not is smart and can be used here for greater readability: 'there is no remainder'.)
Second, in last line, that pattern is clearer coded using dict.get:
More
Python relations can be chained (as in math). check can be written as
g[r][c] == g[r + dr][c + dc] == g[r + 2*dr][c + 2*dc] != '.'
BTW, Guido usually recommends that when you have mixed priority operators, operators binding tighter shouldn't be space-separated from their arguments (see abo
More
It could be, maybe not shorter, but surely sweeter:
from functools import partial
checkio = partial(sorted, key=abs)
More
Line 3 is really superfluous. Just say "for other\_word in words\_set - {word}:". The fact that you named it "other\_words" doesn't help much semantically (especially when other\_word is iterating through it), and it gives the reader one more name (and one more line) to think about.
More
Now when people ask me how dimpleqonx works, I'll just point them to your code. Thanks. :-D
More
Here is your code, halved:
import itertools, operator
def trim(lists):
if lists:
first, *rest = lists
for t in [first] + [first[::-1]]*(first[0]!=first[1]):
for remains in trim(rest): yield [t] + remains
else: yield []
def sqgen
More
Nice twist. You could have gotten away with slicing (or re.sub), instead of that boring replace. ;-)
More