Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
which instantly makes it harder to read, so lets dont do that.
This comment is hidden because it contains spoiler information about the solution
@sean_little the description states: 'If the list is made up of only negative numbers, return 0 instead.' The 'max' would end up being a 0 and thus 0 is returned.
The list can also be replaced with the generator expression directly
approved
This comment is hidden because it contains spoiler information about the solution
Btw,I'am a bit confused. what about all the numbers in the arr are negtive?
agree, elif will be better
.
Yeah, I gave it clever, since it only loops through the array once to find the answer. The syntax might not be beautiful, but the logic is.
I think the code complexity is what's important here.
Even though it's not written in the most beatiful way, complexity is very low.
However shadowing the built-in fucntion? definitely not the best practise.
Good catch, thanks.
I absolutely agree. Thanks for the comment. Even better, I can use
enumerate
instead ofindex
:@lawg
is right, there are a few more reasons why this isn't 'best practice'.Here are the warnings shown on PyCharm for this solution by
@RM84
:@RM84
)','
'max,curr' & '0,0'
'='
'+='
'<'
&'='
'>'
&'='
'max'
You could also replace the line
max,curr=0,0
with something likemaximum = current = 0
.