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

Get more than one longest word 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 :: from_bytes python 
Python :: python IndexError: list assignment index out of range 
Python :: matrix rotation in python 
Python :: python 
Python :: python evaluate string 
Python :: while python 
Python :: python timestamp to string 
Python :: python write subprocess stdout stderr to file 
Python :: split coumn of df into multiple dynamic columns 
Python :: move files in python 
Python :: session in django 
Python :: q fields django Q objects 
Python :: intersection of three arrays 
Python :: ValueError: cannot reshape array of size 98292 into shape (16382,1,28) site:stackoverflow.com 
Python :: django queryset multiple filters 
Python :: python search in json file 
Python :: python outlook 
Python :: how to import nltk 
Python :: example of break statement in python 
Python :: check if key exists in sesson python flask 
Python :: creating methods in python 
Python :: run python script inside bash script 
Python :: python regex match until first occurrence 
Python :: python merge two list 
Python :: sequence with numbers in python 
Python :: print command python 
Python :: excel with python 
Python :: group by dataframe 
Python :: python set cookies 
Python :: python print() 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =