Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gzip
- import random
- import time
- def random_line(afile):
- line = next(afile)
- for num, aline in enumerate(afile):
- if random.randrange(num + 2): continue
- line = aline
- return line
- start_time = time.time()
- with gzip.open("data/pagecounts-20150501-010000.gz") as afile:
- print random_line(afile)
- print("\n--- %s seconds ---" % (time.time() - start_time))
- ===============================================================================================
- Resultat : eu Berezi:CentralAuth/Andre_Engels 1 26936
- --- 28.2244288921 seconds ---
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement