Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- def check_palindrome(file, chunk_size=1024 ** 1 * 512):
- size = os.path.getsize(file)
- left_position = 0
- right_position = size - chunk_size
- with open(file) as fd:
- while not left_position >= right_position:
- fd.seek(left_position)
- left_chunk = fd.read(chunk_size)
- fd.seek(right_position)
- right_chunk = fd.read(chunk_size)[::-1]
- if left_chunk != right_chunk:
- return False
- left_position += chunk_size
- right_position -= chunk_size
- return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement