I am using following code to pickup 10 random lines, however it’s also pickups empty line. I just wanted to exclude empty line while doing selection. and also wants to mark selected line with * as prefix. so next time this code will not pickup any line which start with *.
import random
task = 10
while ( task >= 0 ):
lines = open('master.txt').read().splitlines()
myline =random.choice(lines)
print(myline)
task -= 1
print ('Done!')
The following will randomly select 10 lines that are non-empty and not marked. The selected lines are printed out and the file is updated such that the selected lines are marked (prepended with
*) and empty lines removed.