+ 2

How to return the highest integer value from a list in python

How can I return or assign to a variable an integer with the largest value from a list? Note: The code is the longest word challenge in the Python core tutorial

24th Aug 2022, 4:22 PM
DarkPhoenix15
DarkPhoenix15 - avatar
3 Respuestas
+ 1
So by "largest value" you actually mean "longest word"? There are several ways to accomplish this. One a approach could be this: * create a variable x that will hold the max length and initialize it with 0 * create a variable y that will hold the longest word and initiize it as empty string * iterate over the list * on each iteration, get the length of the current word. If the current word is longer than x, update x with the length of the current word and set y to the current word. * after the loop, print y; it will be the longest word Example approaches: https://www.geeksforgeeks.org/JUMP_LINK__&&__python__&&__JUMP_LINK-longest-string-in-list/
24th Aug 2022, 4:30 PM
Lisa
Lisa - avatar
+ 1
🧚Somya🌹 The longest word challenge(62 code project) in the Python core tutorial
24th Aug 2022, 4:35 PM
DarkPhoenix15
DarkPhoenix15 - avatar