Created
May 28, 2023 01:03
-
-
Save AhmedMohamedAbdelaty/bebeecda9d37cdbd5f97de576e0fd3a9 to your computer and use it in GitHub Desktop.
Line Randomizer Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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