21
Last seen 1 year ago
Member for 10 years, 7 months
Difficulty Normal
This is great solution!
Can you explain why are you using underscore here:
[_] for _ in str(key)]
More
OK, one for loop is enough:
for sym in data:
if sym.isdigit():
digit = True
if sym.isupper():
upper = True
if sym.islower():
lower = True
More
Passing generic exceptions silently is bad practice.
You can wrtie something like this instead:
return max(args) - min(args) if args else 0
or
return len(args) and max(args) - min(args)
More
Hello nkapliev,
at first we have isupper()
at second
[ ]
are redundant
you can use generator instead
return ''.join(l for l in t if l.isupper())
to read more about Iterables vs. Iterators vs. Generators
I recommend to read [this](http://nvie.com/posts/iterators-vs-generators/) and also [
More
You can replace code on lines 2 - 8 with this:
from collections import Counter
letter_dict = Counter(text.lower())
More
You can also write:
return (s[n//2-1]+s[n//2])/2 if n % 2 == 0 else s[n//2]
More
super() super :) it makes me to re-read great article from [Raymond Hettinger](https://rhettinger.wordpress.com/2011/05/26/super-considered-super/)
More
You can rewrite __repr__ like this:
def __repr__(self):
return "Building({0.south}, {0.west}, {0.width_WE}, {0.width_NS}, {0.height})".format(self)
More
you can use **&** for intersection
checkio = lambda first, second: ",".join(sorted(set(first.split(",")) & set(second.split(","))))
More
Hello stranger,
list(str(..
is redundant.
you can do this:
return bin(number).count('1')
More
You can call from string import digits, ascii_lowercase
and then, in stead of writing your alpha, you can use:
digits + ascii_lowercase
More
it's unnecessary (ok I know it's kinda style question) to import everything from string to namespace.
from string import ascii_lowercase
and also we can use generator here
return min(x in text.lower() for x in ascii_lowercase)
More
There is a nice trick, how to [unpack](http://hangar.runway7.net/python/packing-unpacking-arguments) arguments in python.
More
Hello stranger,
if condition:
return True
else:
return False
is same as:
return condition
and one more, str has [endswith](https://docs.python.org/2/library/stdtypes.html#str.endswith)
More
or with generator:
count_inversion = lambda nums: sum(1 for i in combinations(list(nums), 2) if i[0] > i[1])
More