21
Last seen 1 year ago
Member for 10 years, 7 months, 12 days
Difficulty Normal
super() super :) it makes me to re-read great article from [Raymond Hettinger](https://rhettinger.wordpress.com/2011/05/26/super-considered-super/)
More
I like it, simple, but still witty.
Just a golf tip. You can convert number to string like this: `n`
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
Thank's to Michael Hudson we have from python 1.4 - Extended Slices.
You can do:
>>> l = range(10)
>>> l[::2]
[0, 2, 4, 6, 8]
More
Hello stranger,
list(str(..
is redundant.
you can do this:
return bin(number).count('1')
More
There is a nice trick, how to [unpack](http://hangar.runway7.net/python/packing-unpacking-arguments) arguments in python.
More
I tried to use enumerate, but it didn't work. Because of that, I found this from Raymond, I think it can be helpful for somebody:
> Lists are unique in the way they allow mutation during iteration because
indexed lookup allows for a meaningful definition of what should be
done as the list mutat
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
or with generator:
count_inversion = lambda nums: sum(1 for i in combinations(list(nums), 2) if i[0] > i[1])
More
When you want to use
range(len(...
think if you can't use
enumerate(...
instead.
More
Faster and less memory consuming is to use generator, it didn’t have to store the entire list.
return sum(1 for w in words if text.lower().find(w) != -1)
aslo is IMHO better to use as condition
if w in text.lower()
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
You can also write:
return (s[n//2-1]+s[n//2])/2 if n % 2 == 0 else s[n//2]
More