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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -