I know that []
indicates a list in Python. The original example was
[classify_single_case(icmaTrainingData_df,
icmaTargetValues_ss,
i,
5)
for i in icmaTrainingData_df.index]
But for the purpose of this question, we can simplify it as:
[print(i) for i in range(0,5)]
I'm used to normal "for loops", e.g.
for i in range(0,5):
print(i)
I couldn't find it in the official documentation, e.g. https://docs.python.org/3/tutorial/controlflow.html#for-statements therefore without fully understanding it I'm not comfortable with using it.
Can all single statement for loops be enclosed with []
signs? Is this some sort of "code golf" attempt at writing shorter code?