+ 8
Is there any difference between one liners and lengthy codes other than no. of lines?
I've seen plenty of good codes related to assignments.Some coders code a program in 8-10 lines and others just do it in one line! Both the codes work the same but I want to know the inner details of both codes.
9 odpowiedzi
+ 20
Some python functions like any(), all() etc. that allow for very compact code are optimized to be executed very quickly and will probably be faster than (for example) a couple of nested loops that do the same job. So in that way, one-liners might be faster than longer code. But that's not a general rule. A compiler/interpreter doesn't really care how much text it has to process (unless your code consists of thousands of lines of code). The time that is needed to parse the code and "translate" it is negligible. Speedwise, a loop like "for i in range(50): print()" isn't faster than using 50 lines of print(), print(), print(). (I just tested it, they take almost the same time, sometimes 50 lines of code are processed even a bit faster than the loop).
+ 14
Yes.... Almost always one-liner codes are not-really readable 😁
+ 10
Most one liners are made by experienced programmers they have a great understanding whats happening under the hood with types,refrences,objects,regex,ternery ect, There not difficult to make but for a beginner they can look intimidating 😰 i wouldent worry about it too much beacuse many of us prefer the long easy to understand codes.
+ 5
Shorter codes are generly preferred, because they require less storage and usually get processed faster.
However, sometimes longer codes get processed faster, due to how the computer interprets certain commands.
Processing speeds are to do with "inner details", as you say. To find them, you would need to investigate deeply into how a computer reads the code. They would be affected by many things and make a difference only in very complex applications. I would not worry about it until you are quite adept.
For now, just focus on making your code adaptable and easy for humans to read -- which usually means short, neatly spaced out, and with functions to avoid repetition.
+ 5
So, should I happy with my codes?
You can check them out.......
+ 1
It's not matter the only things are your code should be readable and it must be optimised for fast processing and less memory
0
No how
0
the first dud never heard of plagiarism, copy less from google mate