18
Last seen 9 months ago
Member for 9 years, 6 months, 20 days
Difficulty Normal
You can use all logic inside try/except.
try:
st = text.index(begin) + len(begin)
except:
st = 0
And the same for end case.
More
Will be more readable if you use slices for this solution.
More
Why do you use `list.sort(data, key = lambda k: k["name"])` ?
You can use only this one `list.sort(data, key = lambda k: k["price"],
reverse = True)`.
list.sort - not obviously will be nice avoid this construction.
More
Interesting solution, But I think with `while` will be more clear
More
nice solution.
It will be nice to use `string.ascii_uppercase` instead `ABCD...`. It will be more robust code.
More
Interesting approach, I recommend to look on builtin library `string` with property `ascii_lowercase`
More
You may change a some part of code for more readable.
For example,
you may check to %15 firstly and return str(number) in the else block code:
if number % 15 == 0:
return 'Fizz Buzz'
...
else:
return str(number)
More
You may write in one line:
return True if all(elem == list[0] for elem in list) else False
More
I think this solution should be in uncategorized solutions.
Firstly, you may use
from collections import defaultdict
that create dict with all data count
And secondly, you approach looks like
O(n*log(n))
but in general in this category for this issue -
O(n)
More
Looks good for clear solution, but non-effective around big-O.
Looks like O(n**2) for this solution.
More
Looks good, maybe will be better change 5 strings of code in one, for example:
return array[n]**n if len(array) >= (n+1) else -1
And a little refactoring you can check len(array) without more or equal but only more, e.g.:
return array[n]**n if len(array) > n else -1
More
Good solution, but I think you may improve this.
Firstly, you check list is non-empty if empty you will return True.
Secondly, you check if non-empty length list equal 1.
Probably, will be good something like this:
return len(set(elements)) < 2
More
For more readable you might write something like this:
flag = True
if elements:
some your code
return flag
More