os.listdir doesn’t sort files by size directly, but you can achieve this by using os.stat() in combination with sorting functions.