How to write a nested for-loop in one line in Python

A nested for-loop can be written in one line, as opposed to nested blocks.

Solution for How to write a nested for-loop in one line in Python : You can use a nested list comprehension to write a nested for-loop in one line Use the syntax [operation for i in iterable1 for j in iterable2] to run operation for every element i in iterable1 for every element j in iterable2.


how-to-write-a-nested-for-loop-in-one-line-in-python