57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 17 hours ago
Member for 11 years, 6 months, 23 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.
"if (len(data) > 0)" is just "if data"
data[1:len(data)] is just data[1:]
And your whole algorithm is just functools.reduce
And in fact already written in Python core, as "sum" builtin.
More
You could have written list(list(list([a,b]))), the effect would be the same. :-P
More
";" might be funny if everything else was in C style, but "sum" surely doesn't fit there. :-]
More
Nice reducing to addition of natural numbers. :-) pattern can be much nicer written using list comprehension: [i in range(b) for i in range(a)]. ;-)
More
Funny, but: first, Counter is really not needed, max can have key too. And second, tuples can be keys (ordered) - no need for base 42. :-)
More
You're reinventing the wheel. See Counter in collections module (standard library).
More
If you're trying to see how it works: just print(r) between lines 5 and 6. I'm sure you'll see what r is, and then the rest is pretty obvious. (Of course, if there are any questions, just ask.)
More
Sorry, but popping empty stack is not your only problem.
Appending at end is much smarter than inserting at beginning all the time, your dic is "backwards" (aestetics, true, but doesn't it just look wrong to you?:), and those parentheses are duplicated in three places in the code. And oh, that "T
More
LOL. This is the reason why I don't comment my code. :-] There would be more comments than code. :-)
More
Last line is just
return s*(n == 1)
And yes, you could have get rid of that special case (given your hate for special cases) in line 2. For example,
return (s + (not s))*(n == 1)
Here you do need parentheses around not, since it is special in grammar. But "not" being special enab
More