57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 12 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.
Again, min and max are purple. What does it tell you? ;-)
Also, line 4. "if args:".
More
"a.count(b) > 0" is just a very convoluted way to say "b in a".
Also, please drop the semicolon. Your C is showing. ;-P If you want to somehow group lines 2 and 3, it's
txt, cnt = text.lower(), 0
And be a bit more careful with names. First, you don't have to name everything, and second, names
More
Waitaminute. Not even a C programmer would use _that_ many parentheses. Do you maybe come from The Tower of PHP? :-O
More
Here it doesn't matter much, but be aware of [Schlemiel problem](http://en.wikipedia.org/wiki/Joel_Spolsky#Example). ;-)
More
Also, drop the [] inside "".join. Here it doesn't matter much, but it's better to get the right instinct.
There is no need to iterate through list(text)... "for c in text" is completely fine. Not everything is a list (and why do you call it array??:).
More
Why the alias? Pythonic way is calling the constructor same as the type. You don't say to_int("34"), right? ;-P
More
Your WET (Write Everything Twice, antonym of DRY) approach is fascinating. :-P
DRY = lambda canon: lambda w1, w2: canon(w1) == canon(w2)
@DRY
def v1(word):
return ''.join(sorted(word.upper())).lstrip()
# v2, v3, v4 left as homework. ;-)
verify_anagrams = lambda *a: v1
More
Those names are weird. I suppose `div3` (as in, "divisible by 3") would be much better. `mod3` would mean the remainder itself, and that surely is not what you're after.
Of course, you can factor it out:
div3, div5 = (not number%k for k in (3, 5))
Also, you can use namespaces here too:
d
More
You can name that False 3 names in one statement:
has_digit = has_lower = has_upper = False
(And spaces around `=` assignments are really good for easy reading. *Sparse is better than dense.*)
Or, even better, "*Namespaces are one honking great idea -- let's do more of those!*":
has = di
More
... and you're even using it correctly. :-D
(Although that lonely `return` in line 11 is weird.:)
[Of course, you know you can write `array[n]**n`?]
But a more important thing: that docstring. You're doing it wrong. :-)
https://www.python.org/dev/peps/pep-0257/#one-line-docstrings
More
Since you obviously know about `key` kwarg to max (and sorted), it's a mystery why didn't you just
return max(letters, key=text_lower.count)
And of course, you could
from string import ascii_lowercase as letters
And you don't need text_lower, text.lower() is equally readable. :-)
More
I must say I don't understand what are you doing here. Read once more what I've written.
What do you think letters.split() is doing? Try it in interactive shell.
And your "new" function is never actually seen by the testing engine, since right below it, you have the "old" function which redefines
More
Sorry, but doesn't. mapping lambdas doesn't make sense when you have genexps:
all(map(lambda x: cond, seq)) ~~~> all(cond for x in seq)
Simpler, shorter, more elegant, and faster.
Also,
from string import ascii_lowercase as alp
But you already know that probably. :-)
More
Again, too wordy and with strange names (from the perspective of English, `result` is much more common). But generally ok.
More
Don't use int for truncation, it's bad style (Guido tries to deprecate such usage). When floordividing, use the dedicated operator: `n // 2`.
Even better: since you need both // and %, why not acquire both at once:
half, odd = divmod(len(data), 2)
if odd:
return sum(data[half-1:hal
More
This is a standard, and I hope intended, solution for this task. However,
it's interesting to know that Python has a tool for specializing functions
directly: functools.partial. So you don't have to define a new function,
you just construct a partial object from sorted on key=abs, and name it
checki
More
A nice idea, but could be written much more directly. Check [this one](https://py.checkio.org/mission/three-words/publications/hrvoje/python-27/slightly-weird-solution/?ordering=most_voted&filtering=all) for example. :-)
More