For simple statements like this, it's quite pythonic to put it on one line. Even for more complicated statements with ifs and for loops and generators, it is still often pythonic to put it on one line.
It depends on what you're working on. If this function were part of a website backend counting characters in usernames or something, it doesn't really matter at all. But if this is a helper function that is responsible for comparing billions of base pairs in genetic sequencing or part of a stock trading platform where microseconds matter, then you need to rethink it.
that is a smart solve ,, i like it , i know that is don't best practice and there was more solutions is more readable than it's but this is a new practice and a new way for the solution for me, so i like it.
i know my english language is bad :)
Like the clean cut solution! But I think, it defeats the purpose of beginner-friendly critical thinking, breaking down problems etc. Good work nonetheless :)
is there any difference between this two very similar solutions?
For simple statements like this, it's quite pythonic to put it on one line. Even for more complicated statements with ifs and for loops and generators, it is still often pythonic to put it on one line.
YMMV in other languages.
I don't know about industrial programming, but here it is often done like this
Q: How conventional is it to have this on one line over multiple? Apologies if this is a silly question - still learning. :)
It depends on what you're working on. If this function were part of a website backend counting characters in usernames or something, it doesn't really matter at all. But if this is a helper function that is responsible for comparing billions of base pairs in genetic sequencing or part of a stock trading platform where microseconds matter, then you need to rethink it.
Would it matter? I assume itll be a O(2n) vs O(n) but I'm not sure if that's a big deal.
This comment is hidden because it contains spoiler information about the solution
Lol, me too. In case I need to translate it to C later.
that is a smart solve ,, i like it , i know that is don't best practice and there was more solutions is more readable than it's but this is a new practice and a new way for the solution for me, so i like it.
i know my english language is bad :)
I didn`t even know about count method and used loops, lol. Thanks for the best solution!
when you use if nums
python check if the list at least have one element and return true
if list is empty python return false so automatically the if block is not excuted
what's the problem?
Like the clean cut solution! But I think, it defeats the purpose of beginner-friendly critical thinking, breaking down problems etc. Good work nonetheless :)
did the same, so neat!
sweet. didn't think of this.
Loading more items...