def countifstatements(solutionsfile): for function in parse_text(solutionsfile): function.seek(0) ifs = [] for line in function: for f in re.findall("(if.*:)", line): ifs.append(f) ifcount = len(ifs) yield ("if statements", ifcount)
def countforloops(solutionsfile): for function in parse_text(solutionsfile): function.seek(0) loops = [] for line in function: for f in re.findall('(for.*in )', line): loops.append(f) loopcount = len(loops) yield ('for loop count', loopcount)
def counthelpers(solutionsfile): for function in parse_text(solutionsfile): function.seek(0) helpers = [] for line in function: for f in re.findall('(def.*\(.*\):)', line): helpers.append(f) helpercount = len(helpers)-1 yield ('helpers', helpercount)
def countlines(solutionsfile): #import pdb; pdb.set_trace() for function in parse_text(solutionsfile): function.seek(0) yield ('line count', len(function.readlines()))
def countseconds(solutionsfile): #what if modified the parameter to be "solutions" + solutionsfile + "solutions.txt" where solutionsfile would actually be the name of the directory? for function in parse_text(solutionsfile): function.seek(0) yield ('line count', len(function.readlines()))