49
Awesome Team
Philippe Cholet
https://github.com/Philippe-Cholet
Last seen 7 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.
First, you have done it, bravo. But
* I don't like you have to rewrite equip weapons for every subclass of warrior even if it works.
* I recently like try/except[/else][/finally] (for example in scripts for rename files without check if I can) but here in straight fight IMO... readability takes a s
More
if you don't like I call _word(door)_ for each bool in the sum of secret_room, just add
from functools import lru_cache
@lru_cache(4) # for word function remembering the last 4 calls. Then word(door) is in memory.
def word(nb):
...
More
It's original to use a class for that with __sub __ for define distance.
More
math.hypot(x, y) == math.sqrt(x**2+y**2)
def double_distance(point_1, point_2):
dx = abs(point_2[1] - point_1[1])
dy = abs(point_2[0] - point_1[0])
return max(dx, dy) #your code simplify itself.
#And this function is the only distance function you need. It will
More
(x_cr**2 + y_cr**2)**(1/2) # use math.hypot(x_cr, y_cr)
I don't see the point of try/except here. It's more readable with only one assertion in the try (here we don't know what you try to pass), like
try:
i = string_input.index('best')
except ValueError:
i = None #'best'
More
I will have used math.inf instead of 1e10 (or split into 2 cases), and 0 instead of 1e-6 (so r==int(r ) here).
And you can unpack dots with
x1, y1, x2, y2 = *dot1, *dot2 # it's more pleasant.
More
You have the list of values the function take, I have the map of it (with matplotlib).
We can see the part between 0 and 100 repeating multiple times on it.
More
I would see pairs like constant here. I like it.
And why set(sorted(...)) instead of set(...) ? :-D
Maybe
PAIRS = ((0, 3), (1, 2), (4, 5))
cube_rims = lambda cubes: {''.join(sorted(cubes[x]+cubes[y])) for x, y in PAIRS}
More
I like your use of the key argument 'reverse' but `reverse=r%2` is enough.
More
you can do
hand.sort() # and use it instead of s_hand.
I like your set "unique" because for large deck and small hand, your set "unique" is small.
More
And if you want it shorter and if you like next.
from itertools import combinations
tower = lambda cubes: next(size for size in range(len(cubes), -1, -1)
for cur in combinations(cubes, size)
if len(set.intersection(*map(cube
More
Why a while loop here? Instead of
for amount in range(3, len(numbers)+1)
The flag thing...
flag = all(is_match(c[i], c[i + 1]) for i in range(amount - 1)) # short/clear code
If the first thing is false, you don't continue. In your code, you look all i in range(amount - 1).
Well, you can
More
Typically why I don't like map with lambda functions. Comprehension thing is so more readable (and shorter), and good unpacking ^^.
result |= {COL[c] + ROW[r] for c, r in new}
I didn't thought of knight move as manhattan distance 3 (`abs(i)+abs(j)==3`), it's original! Like it!
More
Two comments (I'm in the mood tonight):
* First, range(len(...)) should be (nearly always) enumerate(...). Then no need of itertools.product.
* is_valid is not clear to me.
So new version
def hypercube(grid, target='hypercube'):
prev = None
is_valid = lambda xA, yA, xB, yB: abs(x
More
You don't need cards.sort(), it's already sorted by construction.
cards list can be improved with list comprehension
cards = [(i, i+1) for i in range(deck)] # clearer right?
The big for loop isn't really clear for me.
* i,j are not very well named here I think.
* Given a "i" in hand, you just
More
`sorted` take any iterable, no need of a list so `sorted(set(items))` is enough.
More
Don't like your show method.
'[{1}]{0}[{1}]'.format(self.text, self.fontName)
#or
f'[{self.fontName}]{self.text}[{self.fontName}]'
is more appropriate I think.
Generally, I prefer f-strings but in this case, I prefer the first with 0-1.
And you reinvent the wheel to copy.
More
**1** If you want to write range(len(thing)) you probably should use enumerate(thing).
m_rotated = [[m[j][i] for j in range(len(m))] for i in range(len(m[0]))]
sum_x, sum_y = min(sum(line) for line in m), min(sum(line) for line in m_rotated)
y = min(i for i, row in enumerate(m_rotated)
More
map is usefull for simple mapping. For complicated ones, list/generator comprehension is more readable IMO, and no need of _import chain from itertools_ here with generator comprehension:
return max(Counter(normalize(pos) for cube in cubes
for pos in possib
More
return Counter(''.join(sorted(x)) for faces in cube_opposites
for x in permutations(faces, 2)).most_common()[0][1]/2 # no // ?
More