Answers for "how to random shuffle lines in python"

21

python randomize list

import random

random.shuffle(list)
Posted by: Guest on May-25-2020
0

shuffle text lines python

import random
with open('the_file','r') as source:
    data = [ (random.random(), line) for line in source ]
data.sort()
with open('another_file','w') as target:
    for _, line in data:
        target.write( line )
Posted by: Guest on December-21-2020

Python Answers by Framework

Browse Popular Code Answers by Language