get random line from file python

Solutions on MaxInterview for get random line from file python by the best coders in the world

showing results for - "get random line from file python"
Giulia
10 Jan 2018
1import random
2lines = open('file.txt').read().splitlines() # creates a list with one line per iteù
3randomLine =random.choice(lines) # pick up a random item in this list