57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 9 minutes 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.
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
Line 18 is wrong. rounded gamma is _not_ necessarily equal to 180 - rounded alpha - rounded beta.
BTW why do you reinvent the wheel (in this case, builtin round function)?
More
namedtuple('complex', 'real imag') is better, it supports more operations. ;-)
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
Line 17 is really pointless. :-)
You don't need zip inside map. map(sum, p, dp) is ok.
Start of line 23 can be written: np in m.keys() - visited. Not very useful here, but good to know: keys is a set-like object.
More
ROTFL.
But it would be way more cool if you mapped OPERATION_NAMES to symbols from "∧∨→⊕≡" instead of relying on indexes. This is not maintainable. ;-P
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
It's funny how your naming quickly deteriorated from
most_wanted_letter_alpha # wow, I'm feeling so powerful
to
a # ah, to hell with it already!
:-D
More
And then people tell me that there's no harm in teaching students bubblesort in 21th century. :-/
Well, at least you didn't write digit extraction (converting int to str) manually. ;-] But still, sad.
More
Seriously? You import findall from re just to find out whether `path.startswith('/')`? :-)
More
Line 3 (together with line 16) is such an ugly hack that I'm considering boycotting your solutions. :-P What you're looking for is a len builtin.
Comparisons can be chained. 'if "a" <= c <= "z"', or even better, 'if c.islower()'.
Many names can be given to the same thing: "digit\_count = upc\_lett
More
Why the exception at all? If the text contains no English letters, it's obvious that "a" satisfies all conditions for the return value. ;-P Relevant quote from Zen:
Special cases aren't special enough to break the rules.
Don't invent counter strategy from scratch (well, from dict:). Instead im
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, but here are a few tips:
"D" doesn't really make sense as a return value from check_sequence (what would it mean for a diagonal to be "draw"?:), and it shows in code. Much better would be to just not return anything, and rely on the fact that None is false, while "O" and "X" are not. So:
More
Funny, this is exactly the same length:
safe_pawns=lambda p:sum(bool({chr(ord(c)+o)+chr(ord(r)-1)for o in(-1,1)}&p)for c,r in p)
More
Standard string concatenation approach. For longer messages, you should be
aware of the "Schlemiel the painter" danger (you construct new strings
again and again, longer each time), but for short messages (in this task,
len is at most 1000) it's ok.
More