31
Andrey Solomatin
Last seen 1 year ago
Member for 11 years, 2 months, 8 days
Difficulty Normal
You can use bool as int:
def in_circle(x, y, r):
return r > (x ** 2 + y ** 2) ** 0.5
No need to check all corners just top-right(full) and bottom-left(partial), I missed it in my solution too.
**sum** is bad name for variable.
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
Please dont use global variables.
You use both range and xrange in same cases.
You can simplify code:
# if land_map[x][y] == 1:
# cur_dep += 1
cur_dep += land_map[x][y]
# dx = [1, -1, 0, 0]
# dy = [0, 0, 1, -1]
# for i in range(4):
for dx, dy in zip([1,
More
use string formating it make code more readable:
evalstring = '%s%s%s(%s)' % ("s", "u", "m", data)
More
Looks like you never forget to put coma between strings in list :)
Python parser joins string automatically.
'A' "B" == 'AB'
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
yes, real meh. I can't unsee eighty bucks in you solution. :)
Did you realy need **else:**?
More
Python list are not optimized to pop(0) # remove element form begin, you should avoid this in cycles. Replace it with for or reverse list and use pop() # remove element from end.
For each line of log you traverse over all other lines in log. It is to complex. You can break on time_delta more the
More
you can use builtin function **len** instead of you lambda: **lambda x: len(x)**
removing check at line 2-3 will not affect result.
More
V and S are bad variable names for python.
For multi line docstrings I prefer to start text from second line.
More