0
Using for loop .. how can i chosse fbe longest name in the list ?
2 Respostas
+ 2
Like this (assuming you're using python 2.7, but 3 wouldn't be much different):
lis = ["uuuuuu", "iia", "oooo"]
print max(lis, key=len)
The "max()" function will return the maximum (aka longest/largest) item according to the key (in this case, len or length) so it will print out "uuuuuu" (without the quotes of course).
+ 1
int longestIndex = 0;
chars = 0;
for(int i=0;i < arr.lenght ; i++){
if (arr[i].lenght>chars)
chars = arr[i].lenght
longestIndex=i;
}