Good evening! Sunday I discovered that I will have to learn python, that the subject that I will study will be in this language and can not escape. I studied well this week and managed to get to matrices, but I came across subtleties that I'm still trying to understand. One of the exercises I did today asked me to do a function that would return if a given object belonged to a list, I did "two" functions that follow:
def Pertence1 (item, lista):
return item in lista
def Pertence2 (item, lista):
for i in range(len(lista)):
if (item == lista[i]): return True
return False
This second function was the first one I thought of, as I have as "mother" language C, (if I do not do a function that goes through a list (vector), I even have itching), it almost came automatically to imagine a loop that runs through a list and compare item by item until I find, in a second moment came the first function, which I feel is not exactly a "function" (I am still understanding this concept in python), more simple, objective, fulfilled what the exercise requested, I found in a way, very simple and even obscure, thinking of an immense code, I understand how useful the first one would be. I do not know if with C I learned that a good code, consistent, needs to be robust, hard, with kkk pointers. By making an analogy between English and Portuguese, I feel that if the requirement to learn another language was just vocabulary, it would be enough to decorate the words and that's it, but there is epistemological subtlety between describing the same object in two languages, even though logic is the same to describe. I would like your opinion on.