Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def find_longest_line_length(file_path):
- with open(file_path, 'r') as file:
- lines = file.readlines()
- max_length = 0
- for line in lines:
- line_length = len(line.rstrip('\n'))
- if line_length > max_length:
- max_length = line_length
- return max_length
- # Пример использования
- file_path = 'file.txt' # Путь к текстовому файлу
- longest_line_length = find_longest_line_length(file_path)
- print(f"Длина самой длинной строки в файле: {longest_line_length}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement