39
Axel
Last seen 2 months ago
Member for 2 years, 9 months, 8 days
Difficulty Normal
you can use -x[1] instead of x[1] and omit 'reverse=True'
More
short solution!
btw you can use all possible moves list to remove one 'c +=' line
[(1, 2), (1, -2), (-1, 2), (-1, -2), (2, 1), (2, -1), (-2, 1), (-2, -1)]
More
great solution! btw you can shorten first function to one line
return tuple(...) if tree[1] else return ({tree[0]}, )
More
you may use sorting by tuple (abs(value - one), value) and avoid dictionary using
More
you may avoid comprehension and indexing by key function using
return min(values, key=...)
More
Great abstraction and polymorphism using!
But for my solution I economize with volume(). I made it non-abstract with 0 result )
More
you can use this for alpha shift (need no string module and try-except):
chr(97 + (ord(s) - 97 + delta) % 26)
and next step looks like pack it all to one line )
More
Looks like my first solution...
Btw max(..., key=...) could help to improve code :)
More
По идее костыль возникает из-за того, что когда вы добавляете слово к строке, вы всегда добавляете пробел сзади.
Имхо проще так добавлять слово к строке:
line += ' ' * bool(line) + word
More
It's interesting, but your solution 25% slower than this for sorted list:
return items == sorted(items) and len(items) == len(set(items)) # 0.75
More
Let's start optimization from step_finder():
def steps_finder(x, y):
STEPS = [(1, 2), (1, -2), (-1, 2), (-1, -2), (2, 1), (2, -1), (-2, 1), (-2, -1)]
return [[x + dx, y + dy] for dx, dy in STEPS if 8 > x + dx >= 0 and 8 > y + dy >= 0]
and the tail code (after res = []):
r
More
In the second part of code you may simply replace '()', '[]' and '{}'
strings to an empty string
for i in range(len(expression)):
expression = expression.replace('()','').replace('[]','').replace('{}','')
More
You may improve some constructions:
- sorted(res.items(), key=lambda x: -x[1]) instead of using 'reverse=True'
- use sorting by tuples helps you remove 2 or three lines
More
Splendidly!
But 'reverse=True' looks too heavy )
Hint: you may sort by -value for reverse sorting
More
Thanks for remembering complex numbers for map tasks!
It helps to shrink my solution to 10 lines: https://py.checkio.org/mission/lantern-river/publications/CDG.Axel/python-3/complex-isnt-complex/
More