31
Andrey Solomatin
Last seen 1 year ago
Member for 11 years, 2 months, 8 days
Difficulty Normal
Looks like you never forget to put coma between strings in list :)
Python parser joins string automatically.
'A' "B" == 'AB'
More
You don't need raw string in regexp, and can skip square braces when use \w
You can remove **stripped** variable and return len(...)
You did not care about list values, no need to make any calculation in list creation.
return len([1 for word in re.findall("\w+", text) for m in (filter(w
More
no: **word == other\_word[-len(word):]** yes: **other\_word.endswith(word)**
More
There is function in standard library that do the same as **lambda x: abs(x)** you should use it instead of this lambda.
More
You can put all 3 cycles to product:
for i, j (dj, di) in itertools.product(xrange(N), xrange(N), DIRS):
It is bad practice then program raise exeptions during normal flow.
You can replace **raise** with **continue**
More
To check if key in dict allways use **key in d**.
**key in d.keys()** is less readable and huge overhead.
You can use bool to convert to boolean value
False if stack else True
bool(stack)
len(stack) == 0
More
Do not compare bool with True [proof link](http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#True/False_evaluations)
# bad
if element.islower() == True:
# good
if element.islower():
Use len(data) instead of data.__len__(), and you can just return False
More
same code in more functional style
def checkio(data):
# python 2
head, tail = data[0], data[1:]
# python 3
head, *tail = data #
return head + (tail and checkio(tail) or 0)
More
use string formating it make code more readable:
evalstring = '%s%s%s(%s)' % ("s", "u", "m", data)
More
Just rename function argument no need to add new variable:
def checkio(food):
#food = number
Be consistent use += in both cases
newpigs += 1
pig += newpigs # = pig + newpigs
**pig** is not good name for **pigs**
More
**S**, **V** are bad variable names for python.
IMHO reuse **width** and **height** variable as radius is not good, changing them to names a,c (like it common in math) will be more readable, and will fix line length for lines 12, 14
More
You can use generator expression instead list comprehansion:
all(matr[x][y] == matr[x][y+i] for i in xrange(4)))
and xrange(1,4), no need to compare first element.
More