Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to find the longest string in a list in python

a_list = ["a_string", "the_longest_string", "string"]
longest_string = max(a_list, key=len)
print(longest_string)
Comment

python longest list in list

def longest(list1):
    longest_list = max(len(elem) for elem in list1)
    return longest_list
Comment

how to get more than one longest string in a list python

words = ['hello','sample,'word','about','hey','longes','mikeys']
# the code:
longestWord = max(words,key=len)				# will get the longest word
length = len(longestWord)						# will get the length of the longest word
long_word = [i for i in words if len(i) == length]	# list comprehension thatt will get all the longest word in the list
Comment

PREVIOUS NEXT
Code Example
Python :: how to find ip address of website using python 
Python :: factorial sequence code in python with while loops 
Python :: how to make downloadable file in flask 
Python :: clear terminal in python 
Python :: get all environment variables python 
Python :: erode dilate opencv python 
Python :: python current date 
Python :: hide root window tkinter 
Python :: pandas convert header to first row 
Python :: python cv2 read image grayscale 
Python :: python download image from url 
Python :: jupyter clear cell output programmatically 
Python :: python delete none from list 
Python :: pandas add index 
Python :: python 3 pm2 
Python :: matplotlib clear plot 
Python :: what to do in python when you get pygame.Surface object is not callable 
Python :: python schedule timezone 
Python :: pip install numpy 
Python :: cmd run ps1 file in background 
Python :: make y axis start at 0 python 
Python :: how to add icon to tkinter window 
Python :: max of two columns pandas 
Python :: How to perform run-length encoding in Python? 
Python :: tk table python 
Python :: month from datetime pandas 
Python :: python convert number to base 
Python :: make a zero list python 
Python :: height width image opencv 
Python :: how to rewrite minute in datetime python 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =