+ 2

I don't understand the 3rd and 5th line of this code, can someone help me out please?

words = input() inpt = words.split(" ") a = [] for i in inpt: a.append(len(i)) num = max(a) for j in inpt: if num == len(j): print(j)

15th Jan 2022, 1:25 PM
Abiye Iniabere
Abiye Iniabere - avatar
4 Respuestas
+ 3
3rd line: a=[] Here we are taking an empty list 5th line: a.append(len(i)) Here we are adding the length of i in the list (a).
15th Jan 2022, 1:28 PM
NEZ
NEZ - avatar
+ 1
Are we adding the length of I to the list? .What's the use of the "append"?
15th Jan 2022, 1:30 PM
Abiye Iniabere
Abiye Iniabere - avatar
+ 1
append is used to add the specific element in that list, you can refer to the links: edit]: oops, I didn't answered your first question, yes we are adding the length of the i in the list (length of input). https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/ref_list_append.asp
15th Jan 2022, 1:32 PM
NEZ
NEZ - avatar
+ 1
Thank you ㅤㅤㅤ
16th Jan 2022, 12:15 PM
Abiye Iniabere
Abiye Iniabere - avatar