+ 2
Simplicity Vs Efficiency
I recently encountered a codewars problem . It required a function to remove all the vowels in a sentence : You could do this : vowels = ["a" , "e" , "I" , "o" , "u" ] for i in ___ . if i in vowels: ............... Or you could do : def binary_search( a , vowels): _________ for i in ______ : binary_search(i , vowels ) But then I thought : What is the point of binary search if there are only five vowels . The code would be slightly innefecient but smaller and simpler . So how do you possibly pick .
3 ответов
+ 1
See, when you are participating in coding contests, they mainly pay attention to the total time the code would take for execution and the memory it takes (but the memory is the secondary objective). So, in my opinion, from the heading which you have mentioned, Simplicity vs Efficiency, the contests select efficiency at first hand and then the simplicity.
So, we have to pick that code which works more efficient whether it be bigger or complex.
+ 1
I would suggest you make your code simpler and make it to work. Then change it to be efficient. That way, you will get a working code and make it efficient and you'll get more ideas to make it more efficient
0
I remember something in PEP__ that said "simple is better than complex "