Simplicity Vs Efficiency | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 .

7th Nov 2021, 2:43 AM
Richard
Richard - avatar
3 Answers
+ 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.
7th Nov 2021, 4:52 AM
Adi Nath Bhawani
Adi Nath Bhawani - avatar
+ 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
7th Nov 2021, 4:53 AM
Rishi
Rishi - avatar
0
I remember something in PEP__ that said "simple is better than complex "
8th Nov 2021, 4:15 AM
Richard
Richard - avatar