57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 14 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.
Obligatory Youtube link: https://www.youtube.com/watch?v=o9pEzgHorH0 :-)
More
It could be even easier. You should usually put normal cases first, exceptional ones later.
max(args) - min(args) if args else 0
Or, you can exceptionalize inwards:
max(args, default=0) - min(args, default=0)
:)
More
chain(*map(f, l))
is what you're probably looking for. ;-)
(And it has nothing to do with ChainMap.:)
More
Instead of int(blah/2) you can use blah//2 (or even blah>>1). And you don't need ==1 on len(x)%2. BTW nice smuggling of x.sort() across the lambda. ;-)
More
At first sight, this is usual high-order functional stuff. But there are a few puzzling details, in the form of code that should do nothing, but without it, the solution doesn't work. :-]
* Why is that "if (push, pop, peek)" there? 3-tuple should always be true, right?
* Why is that "and (yiel
More
Why not simply "return l == list"? Lists are equal, not only their lengths.
More
You could have written `range(ord("a"), ord("z")+1)` for maintainability. :-D
More
Nice usage of time module.
conv_dict could be much less repetitive if you looked up things like this:
m = int(mv) * conv_dict[mm.rstrip("s")]
(New TransformDict might help you in Py3.5, if it makes it there.;)
And of course, that code repeated twice should be factored out as a function, just
More
You're aware that you wrote the same thing three times? :-)
More
That counting from 1 at every step feels forced a bit. Python naturally counts from 0.
For "a in bla1 and b in bla2 and c in bla3"... you might wish to learn about sets. Precisely, sets of tuples.
In your inner functions, you don't need lines like 25 and 26. Python returns None by default, whi
More
I like it too. :-) Of course, it can be refactored (to remove repetition) as
sum(((t-f).days+(f.weekday()+i)%7+1)//7for i in(0,1))
:-]
More
Nice recursion. :-)
sorted. Lose the brackets. You know the drill. ;-)
In fact, I think this would be a good place to teach you about enumerate.
for index in range(len(sequence)):
do something with index and sequence[index]
is pythonically written as
for index, elemen
More
> Output: The list of integers.
Yeah, right. :-P
BTW, I'm quite sure I tried a generator anyway (a long time ago), and it didn't work. Did you change something?
More
Nice. If it had a space after the comma in line 1, it would be perfect. :-P
More
Ok, this puzzled even me. Not in what it does, but how did you think of this. :-D
More
This is a nice example of how chaining can help you write better code.
First, x == 1 and y == 1 can be written as x == y == 1.
Then you see you have it also in equivalence.
if x == y == 1 or x == y == 0:
Then you see you can factor out x == y.
if x == y in (0, 1):
Then you realize that
More
LOL. I'm beginning to like you. You have some potential. ;-)
(Of course, you're aware of bin builtin? Just checking...)
More
Next time someone tells me Python is a functional programming language, I'll show them this. :-DD
More