Answers for "python longest word in string"

1

Write a python program to find the longest words.

def longestword(filename):
	with open(filename,'r+') as f:
		words = f.read().split()
		max_len_word = max(words,key=len)
		max_len = len(max(words,key=len))		
		print('maximum lenth word in file :',max_len_word)
		print('lenth is : ',max_len)

longestword('file1.txt')

or 

def longest_word(filename):
    with open(filename, 'r') as infile:
              words = infile.read().split()
    max_len = len(max(words, key=len))
    return [word for word in words if len(word) == max_len]

print(longest_word('file1.txt'))
Posted by: Guest on November-29-2020
0

python longest word in string

def find_longest_word(word_list):  
    longest_word =  max(word_list, key=len)
    return longest_word
Posted by: Guest on November-02-2020
0

how to find the longest string python

max(a_list, key=len)
Posted by: Guest on November-22-2020

Code answers related to "python longest word in string"

Python Answers by Framework

Browse Popular Code Answers by Language