57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 13 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.
set([left, right]) ~~~> {left, right}
Or better yet, lines 3~6:
sets = [set(link.split("-")) for link in network]
Lines 9~12:
if i is not j and i & j:
Lines 14~17:
return any({first, second} <= i for i in sets)
And of course, algorithm is horrible. :-P
More
Argh, code triplication. :-P Wasn't it easier to collect them all in one place? Or better yet, write a generator?
def lines():
yield from gr
yield from zip(*gr)
yield [r[i] for i, r in enumerate(gr)]
yield [r[~i] for i, r in enumerate(gr))]
for line in lines(
More
WOVELS = set("AEIOUY")
CONSONANTS = set(string.ascii_uppercase) - WOWELS
samekind = lambda a, b: {a, b} <= WOWELS or {a, b} <= CONSONANTS
zip(word, word[1:]) is enough.
c not in separators. And you very rarely need parens after not.
What do you mean, "tried c.isalpha()"? Didn't work? :-)
All in
More
bin(number)[2:] ~~~> format(number, "b")
int(b) for b in blah ~~~> map(int, blah)
More
Lines 2~4:
feed, birds, new_birds = number, 0, 1
Line 7 really should have been written
if feed <= birds:
More
Nice hack with %180. :-D Bare excepts are usually frowned upon, but this is obivously a quick&dirty solution.
More
iElement is a very strange name. Do you come from the Kingdom of Nouns (also known to its denizens as Java)? :-)
More
Your complicated protocol has a name: **and**. ;-)
return digit and upper and lower and len(data) < 10
And a nitpick: you don't need + in your regexen. ;-)
More
Line 13 is the right idea, but can be taken much further. Do you notice that you're always accessing FIRST_TEN and oneToNineteen (BTW why not till19?:) with offset 1, and OTHER_TENS with offset 2?
FIRST_TEN[:0] = [None]
OTHER_TENS[:0] = [None, None]
(or just change them inline). And then u
More
Do you really need to find if number of elements is odd _before_ you sort the list? Last time I checked, .sort didn't change the length. :-)
if len(data) % 2:
And yes... what exactly did you intend to accomplish with line 3? Are you really saying that listLength is somehow clearer than len(dat
More
Instead of returning [], you should return None. That is, just delete lines 4 and 5.
def outcome((a, b, c)):
if a == b == c != '.':
return a
Why do you turn everything into a list? For example, line 9 is completely unnecessary. Not to mention that the whole first part is un
More
Line 8: [] is a strange name for a set. That's the main problem with your comments anyway: they are incredibly misleading sometimes. You probably come from some programming language where it is much more important to explain things to compiler than to the human reader. In Python it's the opposite: i
More
Line 10: horrible. Refactoring? "Extract variable"?
move = lambda t, d: chr(ord(t) + d)
for x, y in pawns:
up = move(y, -1)
if {move(x, 1) + up, move(x, -1) + up} & pawns:
count += 1
More
Unfortunately, this doesn't work if data starts with 0. Please use inline ..if..else.. instead of that ..and..or.. trick.
More
Line 5 doesn't work if super() is empty. :-( But it can be rescued as gyahun_dash showed:
set().union(*self)
More
Could be more thumbs if you used pawns & {blah} instead of .intersection().
More
ROTFL. Although it has some cases where it doesn't work (there are other chars in letter and number blocks that are not letters nor numbers), it did make me laugh. You can make it even more cryptic if you want:
checkio = lambda data: len(str(len(data))) > 1 >
__import__("functools").
More
i, enumerate, if, duplication in lines 11 and 13... just so you can have one char less at the beginning. It doesn't pay off. You can just slice the result by [1:].
That replaces at the end are probably nicer written using .translate. But not a big deal.
Lines 7 and 8: use divmod.
format is also a
More
It's nice to know I'm not the only one with the problem of people who think "Clear" comes from "C". :-))
More