23
Last seen 2 years ago
Member for 8 years, 8 months, 28 days
Difficulty Normal
Hi,
You forgot to remove the regex import.
I really like how you used the new assignement syntax. Very nice!
More
Hi,
Just a remark.
The code
```
if condition:
return True
else:
return False
```
can be replaced by `return condition` (much simpler).
Similarly,
```
if condition:
return False
else:
return True
```
can be replaced by `return not condition`.
More
Hi,
Just a remark. `True if condition else False` can be replaced by `condition`. Similarly, `False if condition else True` can be replaced by `not condition`.
More
Very nice use of regex.
Also, I didn't know it was possible to combine string types (raw and f-strings).
More
Hi,
Your solution is correct but a bit long and inefficient. Sorting a list takes O(n log(n)) while looknng for a minimum is just O(n). It's not that bad because sorting is still reasonably fast but you are adding unnecessary complexity.
To improve your code, you could do a single for loop. In it
More
Hi,
Instead of `split`, you could use `find`, which is more efficient in this case since we only need to get the first "word" after =.
if index == -1:
return ""
end_index = cookie.find("; ", index)
return cookie[index:] if end_index = -1 else cookie[index:end_index]
More
Hi,
You're computing `len(text)//2` three times. It would be nicer to use a local variable to store this result.
More
Hi,
You're scanning the whole map three times. A more eficient way would be to scan the map once to find the objects, then to compute the distances.
Also, `sorted(a, b)[1]` is just `max(a, b)`.
More
This solution is much more elegant and efficient than most of othesr which unnecessarily make extensive use of zip and sums.
More
Instead of `n > len(array) - 1`, I find `n >= len(array)` more natural. But that's just a detail.
More
Hi,
The `return None` is unnecessary. Since either the `if` part or the `else` part is executed, the `return None` can never be reached.
More
Using `range` is a bit overkill. A single < is enough. Or `0 <= n < len(array)` if you want to check the lower bound too.
More
`is_alive` should be a "property".
To keep it simple, a property is a function which can be invoked like an attribute.
Here's the syntax:
@property
def is_alive(self):
# return something
More
Hi,
Did you know that to get a number with two decimal digits, you can just use `round(number, 2)`?
More
Hi,
There's a very small modification you could make to improve your code.
`len(new_line[0:j])` is just `j`.
.
More
Sure.
With your algorithm, you check every value between the min and the max. If max - min = 1,000,000,000, you're going to check 1,000,000,000 numbers even if the array has only two elements.
If you sort the array first, you only need to check pairs of consecutive numbers in the array. If their d
More
Hi,
You can improve your solution by storing the characters' position in the dict instead of the occurrences. Then you can replace the while with a constant-time expression. That'd make your algorithm linear-time.
Also, in the last if, you can keep the best head and tail and generate t in the retu
More