40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi,
1. You don't need that `lambda`. You can use _mul()_ from `operator` module or simply _int.\_\_mul\_\_()_.
2. You could use _map()_ and _str.replace()_ instead of that list comprehension:
return reduce(int.__mul__ , map(int, str(number).replace("0", "")))
More
Hi, one tip: When you are unpacking values and don't use some of them, you can use _ instead of adding dummy names:
# E. g.
phonedate, _, seconds = call.split()
# instead of
phonedate, phonetime, seconds = call.split()
More
Hi, one comment: I would replace lines 13-15 with one line:
# You can apply map(int, ) directly on splitted_data
# and use it as argument of date
year, month, day = map(int, splited_data[0].split('-'))
# In fact you can eliminate these these three variables
call_data
More
Hi, comments are fine, but they make the code less readable. Splitting to paragraphs would make it more readable. E. g.:
# To simplify the code, we use a defaultdict of lists that will contain
# one entry per day containing all the minutes used by calls
daily_calls = defaultdict(li
More
Hi, nice solution. There's one thing: As you don't use _time_ variable, you could write:
data, _, seconds = i.split()
More
Hi, it's very easy to read ;) I have two little comments:
1. You don't use the _t_ variable, so you could write:
d, _, s = call.split(' ')
2. But you could use it to reduce duplication:
t = math.ceil(int(s) / 60)
if d not in seconds:
seconds[d] = t
...
More
Or a big one? :D
1. Look at _extended slices_: `array[::2]`
2. _sum()_ built-in function: `sum(array[::2])`
3. You could write `i += 2`
More
Hi, a bit shoter version:
def count_neighbours(grid, row, col):
sg = lambda t: save_get(grid, row + t[0], col + t[1])
return sum(map(sg, ((-1,-1), (-1, 0),
(-1, 1), (0, -1),
(0, 1), (1, -1),
(1,
More
Hi, actually those comments make it less readable. A few empty lines would make the thing. E. g.:
# format odd items (n_:n_:n_) from len(4) to len(3) representation
form = list(map(lambda x: x[1][1:] if not x[0]%2 else x[1], enumerate(mors)))
# join hh, mm, ss, add ' : ', and remov
More
Hi, I know... CTRL+C, CTRL+V is easy, but have this one
int(i[19:])//60 + bool(int(i[19:])%60)
two times... hmmm
More
Hi, this is a bit "overparthesized", especially this:
str((int(i[1])-1))
# why not:
str(int(i[1])-1)
Anyway, line 5 and 6 contains almost the same code. I've been playing a bit and reduced it to this:
return sum(any(columns[columns.index(i[0]) + n] + str(int(i[1])-1)
More
Hi, ... as if I was looking of code of my colleague :) It's nice to have comments, but without visual separation they make code hard to read. Blank lines are useful, but some people (including my colleague) don't like them. E. g.:
# Splits each call into usable information
duration = [
More