49
Awesome Team
Philippe Cholet
https://github.com/Philippe-Cholet
Last seen 29 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.
`[x for x in y]` is equivalent to `list(y)` but here you don't even need a list. A string is a good enough iterable: `int(max(str(number)))`
More
If you think Army like a list, consider
class Army(list):
#Army is now a list with all methods from list and your mind.
#So no need of init, getitem, len, remove.
More
In a more pythonic way...
x,y = max(dict1.keys(),key= lambda x:dict1[x])
# keys method is not really useful, I don't remember any situation where it is.
x, y = max(dict1, key = dict1.get) # your lambda function already exists for dicts.
if len(dict1) == 0:
# or
if not dict1
More
I don't see the point of the `~1` instead of `-2` except to make the code a bit weird. Miss I something here?
More
if `len(els) < 3` then `range(2, len(els))` is empty so lines 7-8 are not required.
More
As I did for "replace first", I add this fourth solution:
```python
# numpy.roll generalize our function.
import functools as fn
import numpy as np
replace_last = fn.partial(np.roll, shift=1)
```
More
Intervals are already sorted (see description), so `sorted(set(...))` is a bit useless.
More
First, line 10 can be written `return f'({self.x}, {self.y})'`.
Second, I don't really see the point of OOP here, you just need `range(...)`. It's probably because you thought about `chain(*map(...))`. List comprehension is enough here.
Like this (if you want `chain`):
chain.from_iterable(ran
More
I would use "for/else" instead of "flag". What do you think?
for i in range(1, 101):
for j in range(4):
if i % prime[j] != attempts[j + 1][0]:
break
else:
return [2, i]
More
**EDIT:** in the arguments are of the **same** lengths.
More
def navigation(seaside):
for i, row in enumerate(seaside): # n/s coordinate
for j, item in enumerate(row): # w/e coordinate
if item == 'Y':
cY = i, j # now it's a tuple.
elif item == 'C':
cC = i, j
More
Possible improvement (decrease the number of possibilities). Between line 27 and 28, put that:
# Only keep keys when the value is useful (not empty sets)
# But put useless cannons (can't shoot any enemy) at North...
reach = [({k: v for k, v in dirs.items() if v} if any(dirs.values())
More
Use global variables is usually a bad idea, like here. Honestly it should NOT have pass tests. You only pass them because of "check" part work, and little tests did not warn you about it.
assert isometric_strings('add', 'egg') == True
dict == {'a': 'e', 'd': 'g'}
assert isometric_strin
More
width = len(w1[0]) # at begining, can be good for readability. And I use it later.
`range(len(...))` should be forbidden ^^ `enumerate` is good enough.
for row in wl:
for j, ch in enumerate(row):
if ch == '#':
layers[j] += 1
Your way to find weakest spot
More
Don't you think you spam published solutions?! 6 (very very similar) published solutions.
More
**First**
f2 = lambda x, y: any(True if (x + i, y + j) in X else False ...
# please write it...
f2 = lambda x, y: any((x + i, y + j) in X ...
**Second**, right now for me on checkio, I can't see after 107 characters width without pain ^^
For readability, PEP8 insist on width, width no
More
First, you use numpy, I like it but '3rd party' is there for such solutions.
Your `... == 0` is already a boolean, so you can just write
return np.count_nonzero(np_matrix + np_matrix.T) == 0 # True when it's True, False when...
# or
return not np.count_nonzero(np_matrix + np_matrix.T)
More