Advertisement
anasse_hassala

Untitled

May 30th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. import gzip
  2. import random
  3. import time
  4.  
  5. def random_line(afile):
  6.     line = next(afile)
  7.     for num, aline in enumerate(afile):
  8.         if random.randrange(num + 2): continue
  9.         line = aline
  10.     return line
  11.  
  12. start_time = time.time()
  13.  
  14. with gzip.open("data/pagecounts-20150501-010000.gz") as afile:
  15.     print random_line(afile)
  16.  
  17. print("\n--- %s seconds ---" % (time.time() - start_time))
  18.  
  19.  
  20.  
  21.  
  22. ===============================================================================================
  23.  
  24. Resultat : eu Berezi:CentralAuth/Andre_Engels 1 26936
  25.  
  26.  
  27. --- 28.2244288921 seconds ---
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement