Advertisement
plarmi

pythonwork_14_4

Jul 9th, 2023
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. def find_longest_line_length(file_path):
  2.     with open(file_path, 'r') as file:
  3.         lines = file.readlines()
  4.        
  5.     max_length = 0
  6.     for line in lines:
  7.         line_length = len(line.rstrip('\n'))
  8.         if line_length > max_length:
  9.             max_length = line_length
  10.    
  11.     return max_length
  12.  
  13. # Пример использования
  14. file_path = 'file.txt'  # Путь к текстовому файлу
  15.  
  16. longest_line_length = find_longest_line_length(file_path)
  17. print(f"Длина самой длинной строки в файле: {longest_line_length}")
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement