40
Last seen 22 hours ago
Member for 9 years, 11 months, 3 days
Difficulty Advanced
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
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, 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,
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,
1. look at _filter()_ and _str.join()_.
2. __str__ is immutable in Python, therefore is not the best type for accumulation.
More
Hi, it would be faster and more memory efficient with _sum()_:
count_words = lambda text, words: sum(w in text.lower() for w in words)
More
Hi, that `regex` dictionary is redundant:
regex = re.compile("[A-Z]")
...
if regex.match(c):
out += c
In fact you don't need regex at all:
return "".join(filter(str.isupper, text))
More
Hi, why not:
return bool(re.search(r'([a-zA-Z]+) ([a-zA-Z]+) ([a-zA-Z]+)', words))
More
Clean?
def checkio(array):
return sum(array[::2]) * array[-1] if array else 0
More
Hi, nice :) Can you do it without `if` and `try...catch`.
More
Hi,
1. you could import `ascii_uppercase` from `string`.
2. Instead of lines 8-11 you could write this:
checks.append(item in text)
3. Or instead of 7-11 you could write:
checks = [item in text for item in alphabet]
4. Instead of lines 12-14 look at _all()_:
return all(checks)
More
Hi, lot of redundancy there
1. that `if...else` is redundant:
return len(password) >= 10 and match and match1 and match2
2. Or lines 4-6 contains the same pattern.
More
Hi, if you have to use `\` there is something wrong :)
return list.__eq__(*[[x for x in sorted(w.lower()) if x != " "] for w in (f, s)]) # :)
More