Skip to content

Instantly share code, notes, and snippets.

@AhmedMohamedAbdelaty
Created May 28, 2023 01:03
Show Gist options
  • Save AhmedMohamedAbdelaty/bebeecda9d37cdbd5f97de576e0fd3a9 to your computer and use it in GitHub Desktop.
Save AhmedMohamedAbdelaty/bebeecda9d37cdbd5f97de576e0fd3a9 to your computer and use it in GitHub Desktop.
Line Randomizer Python
import random
# Read lines from input.txt
with open('input.txt', 'r') as f:
lines = f.readlines()
# Shuffle the lines randomly
random.shuffle(lines)
# Print shuffled lines with a newline after each line
for line in lines:
print(line.strip())
print()
# Write shuffled lines to output.txt with a newline after each line
with open('output.txt', 'w') as f:
for line in lines:
f.write(line.strip() + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment