57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 14 hours ago
Member for 11 years, 6 months, 6 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.
Line 7 can be written: if num in cur_alpha.
Or better yet, use EAFP instead of twice going through. Just remove lines 6~8, change .find to .index in line 10, catch ValueError and return -1 in that case.
More
You can use sum builtin instead of manual management of count, and you can use enumerate instead of manual index management. ;-)
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
Either make verify_anagrams a lambda, or make s a def. It's slightly inconsistent this way. :-)
More
See all builtin. It will help you. ;-)
all(re.search(p, data) for p in "[A-Z] [a-z] [0-9]".split()) and len(data) > 9
More
... except if array is empty, then it cannot. ;-D
More
Only few things...
Names starting with uppercase are usually not used locally.
In line 4, look at the set.intersection_update, or shorthanded &=.
Or you can eliminate the loop with
return max(set.intersection(*map(Factor, args))
It's practically direct translation:
max ~~
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
This is a nice place to teach you about *-calls.
First, i+j\*1j is complex(i,j). That is not so exciting. But if a=(b,c), complex(b,c) can be written as complex(\*a). In your case, since len(a)==3, complex(\*a[:2]) would do the job. Functions can take their (last) arguments from any sequence, for
More
An obvious solution. Just a few hints:
frozenset([int(s[0]),int(s[1])]) is frozenset(map(int,s)).
frozenset([n,i]) (better written as frozenset({n,i})) really ought to be assigned to a variable, it's used in lines 8, 9 and 13.
BTW instead of closing over ts and manually screwing it into pla
More
Lines 4,5,6:
digits = lowers = uppers = 0
Line 1: unnecessary. :-)
Lines 8~13:
digits += c.isdigit()
lowers += c.islower()
uppers += c.isupper()
or if you insist on using unbound method, remove initialization and just say
digits = sum(map(str.isdigit, data))
Lines 15~18:
More
Argh, float("%.2f" % x)... you really should use the function "round". ;-)
More
I put those chars @StefanPochmann generously provided me to good use - traded them for spaces at a favorable exchange rate. :-D
[Of course, now someone will make a 'vfn' solution without spaces. But that's just too predictable.:]
More
Wasn't it easier to do that `set(connection.split("-"))` thing only once? :-)
Also, `break else return` is a powerful pattern that's better than bool flags.
See [my solution](https://py.checkio.org/mission/find-friends/publications/veky/python-3/tinus-trotyls-pythonified/) for implementation. :-)
More
More importantly, every
if cond:
return 1
else:
return 0
is simply "return int(cond)".
Switch is not if/elif/elif... here, but simply a dict. But this is not so important as what I said above.
More
You are using Python3, use it properly. You know about // (line 9), use it in line 5 too.
i1 = a // 2
i2 = i1 - 1
(int - 1 is always int:)
More