Would it be maybe better to use a .expect("Array is empty") to handle that case for general use?
It's not a best practice though, if there is a unwrap there is no best practice imo
Your solution is correct, unlike the currently highest rated "Best Practices" one (Jan 2025). Floating point maths is not accurate.
the description says the input is always valid
What if there is unicode char as the first element? What happens if the input is an empty string which is then unwraped?
For anyone wondering why you can use bool as 1 and 0 https://github.com/python/cpython/blob/main/Doc/c-api/bool.rst#id3
Booleans in Python are implemented as a subclass of integers.
Nice one! Got something new for me, thx :)
haha! Nice one Just Waiting to see this kind of clever solution.
Lean and mean!
Yes. True is 1
great work actually
Beautiful.
Voted "best practices" because it only does as much calculation as necessary, unlike the most popular solution. Well done.
This comment is hidden because it contains spoiler information about the solution
I liked the "str::to_string" part. Clever!
Loading collection data...
Would it be maybe better to use a .expect("Array is empty") to handle that case for general use?
It's not a best practice though, if there is a unwrap there is no best practice imo
Your solution is correct, unlike the currently highest rated "Best Practices" one (Jan 2025). Floating point maths is not accurate.
the description says the input is always valid
What if there is unicode char as the first element?
What happens if the input is an empty string which is then unwraped?
For anyone wondering why you can use bool as 1 and 0 https://github.com/python/cpython/blob/main/Doc/c-api/bool.rst#id3
Nice one! Got something new for me, thx :)
haha! Nice one
Just Waiting to see this kind of clever solution.
Lean and mean!
Yes. True is 1
great work actually
Beautiful.
Voted "best practices" because it only does as much calculation as necessary, unlike the most popular solution. Well done.
This comment is hidden because it contains spoiler information about the solution
I liked the "str::to_string" part.
Clever!
Loading more items...