49
Awesome Team
Philippe Cholet
https://github.com/Philippe-Cholet
Last seen 50 minutes ago
Member for 6 years, 2 months, 27 days
Difficulty Advanced
I was a math teacher in France for two years. I'm currently reconverting to IT, I'm here to improve my Python skills, and practice English.
No need of itertools.chain
counts = Counter(ring for cube in cubes
for ring in rings(cube))
you can do rings without while loop:
i = ring.index(first)
ring = ring[i:] + ring[:i]
I did this rotation like you at first.
Ah and you can change rings in generator:
More
A little improvement on the end:
return any(fill(row, col, '')
for row in range(len(grid))
for col in range(len(grid[0])))
# Not really useful here but you should considerate use enumerate(...) instead of range(len(...))
map is good if it's a simple one. List c
More
Dict comprehension is good too...
Every single time you want to use range(len(...)), you probably should use enumerate(...) instead. Here, for example, it can be this. Enumerate rows, enumerate cells of the i-th row, put (i,j) when cell is the letter.
all_letters = {letter: [(i, j) for i, row
More
I didn't understand your solution at first, because of my ignorance of scipy (and then scipy.ndimage).
But now I really like it, you inspired me a solution for Bacteria Colonies (challenging task) on Incinerator Island. Not a compact solution but a natural solution I think. A bit more complicated b
More
all() is really good
No need of brackets here: generator comprehension is good too. len(m**[i]**) useless here because m is a square matrix.
all(m[i][j] == -m[j][i] for i in range(len(m)) for j in range(len(m)) )
More
You seem to like OOP now. I don't understand all of the code, it seems complicated. Well I was looking for connected components too (with DFS, you it's BFS) but I didn't store many things like you (grid, graph, new graph, ...).
**_Now some improvements I suggest:_**
You can change connected_compon
More
Lines 15-20 in a else and 'return nothing' can disappear :)
I never used collections.defaultdict yet, I don't really see the goal of it. Dict comprehension seem to be enough for me to create a graph.
graph = {(r, c): adjac(r, c) for r, row in enumerate(grid)
fo
More
I like your idea to search speeds from both sides (well if I understand it enough ^^).
Slicing make a copy so: I would use `reversed` instead of slicing `[::-1]` and use `islice` instead of `[i:i+n]` because you imported it.
speed_braking = reversed(speed_change(reversed(sections))) #and simpl
More
from typing import Iterable
def is_ascending(items: Iterable[int]) -> bool:
return all(x>max(items[:i+1]) for i,x in enumerate(items[1:]))
should be enough because `all(empty iterable) == True`.
You do many slicing (so a copy of items with every slice), don't like it.
More
`map` is good if it's a simple one. Comprehension thing is more readable, shorter for more complicated mapping.
I only do `map` if the function I want apply have a name (and if I don't need to change the result into list, set... I don't do `list(map(function, iterable))`, I prefer `[function(a) for
More
First, **congratulations on making your first generator!** I think you understand how this works now.
If you don't want `i` but `i+1`, `range(1, len(operations)+1)` or in my version `enumerate(operations, 1)` (for a start at 1).
I did a generator at first too (probably influenced by you telling me
More
Like it!! Probably because it's nearly mine and I already like it. Three comments
* Good name `stack`. I don't remember how I named mine.
* You write `stack.append(el)` in both if/else.
* `yield from reversed(stack)` is more clear it's reversed than with `pop()` IMO. But then `stack = []` is requir
More
I started to think I would not see `list.extend(range(...))`.
But you can unpack tuples from items by changing the line 5 into
for start, stop in items:
# and delete the line 6.
More
Like it but an iterable is enough. :D
def checkio(array):
for number in array:
try:
array.index(number, array.index(number) + 1)
yield number
except ValueError:
pass
More
I agree it's awful ^^. I tried some improvements. Happy new coding year!
from math import ceil
def available_coins(price, denominations):
for i in sorted(denominations):
if i <= price:
for _ in range(price // i):
yield i
def chec
More
line 32:
folders = folders[:-1] # you do an entire copy of the list
# or
folders.pop() # just pop last element, usual for lists.
line 20: `char in '-._~'`
line 9: `first_rule = url.lower()`. No need of line 6, it's already clear it's converting to lowercase.
line 21-22: I like your w
More
Well numpy is good but it's more for "3rd party" category.
def checkio(matrix):
a = np.array(matrix)
b = - np.array(a.transpose())
return (a == b).all() # it's already a boolean, so just return it.
It's great
More
You can write `if matrix[i][i]:` instead of `if matrix[i][i] != 0:`. It's a python thing.
Don't see the point of `* (-1)`, just put a `-` before like `- matrix[i][j] == matrix[j][i]`.
`matrix[i][j] * (-1) == matrix[j][i]` and `matrix[i][j] == matrix[j][i] * (-1)` are the exactly the same.
Final
More
First, I'm glad you liked it. You probably spent a lot of time on it.
There is ROCK, GEMS, MINES, ICE and ROUGH places in same proportion I think. You go only on GEMS, ICE and ROUGH places so 60% of the map (80% if you go on mines) if this can help you decrease the naive upper bound. Then, thanks t
More
Thanks for the use of scipy, I should look at it more carefully, great algorithms are in this `scipy.sparse.csgraph` module.
You can compute cities in a line if you want. For example
cities = sorted({city for *start_end, _ in costs for city in start_end})
# or
cities = sorted(set.union
More