python - Combining for and if loops -
i have code:
num_for_loops = 0 line in lines: if line.strip().startswith('for '): num_for_loops += 1 return num_for_loops
i need condense down little lines possible. there way combining , if statements? context irrelevant.
num_for_loops = sum(line.strip().startswith("for ") line in lines)
since you're returning num_for_loops
suppose want
return sum(line.strip().startswith("for ") line in lines)
Comments
Post a Comment