Which python snippet is better? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Which python snippet is better?

I've coded the answer to the 'longest word' challenge in two ways. (See my profile, or i can paste it here if its easier) First came the condensed version, which has a line full of nested functions. Then I duplicated it and split each function step out using a variable. Which version would be more efficient, and which is best to use in the real world?

20th Oct 2020, 7:35 AM
Zain Craxford
Zain Craxford - avatar
1 Answer
+ 4
As far as time complexity goes they are about the same O(n). The condensed uses slightly less memory. In reality the difference between the 2 is negligible. So you use the code that is cleaner, easier to read and understand.
20th Oct 2020, 7:51 AM
ChaoticDawg
ChaoticDawg - avatar