import time """ Ukol: Na zaklade casu vyhledavani radku pomocĂ­ "if keyword in line:" a "if line.count(keyword) > 0:" rozhodnete, ktere z reseni je lepsi. """ def PyGrep1(keyword, filename): counter = 0 with open(filename) as fh: for line in fh: line = line.rstrip() if keyword in line: counter += 1 #print(line) #print(counter) def PyGrep2(keyword, filename): counter = 0 with open(filename) as fh: for line in fh: line = line.rstrip() if line.count(keyword) > 0: counter += 1 #print(line) #print(counter) start_time = time.time() for i in range(1000): PyGrep1("krakatit", "krakatit.txt") print("--- {} seconds ---".format(time.time() - start_time)) start_time = time.time() for i in range(1000): PyGrep2("krakatit", "krakatit.txt") print("--- {} seconds ---".format(time.time() - start_time))