Python Forum

Full Version: Python institute associate sample exam question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Can someone please explain the syntax and the logic of the below code? Especially the first line.

How many stars (*) will the following snippet send to the console?

lst = [[c for c in range(x)] for x in range(3)]
for x in lst:
     for y in x: if y < 2:
          print('*', end='')
The first line is called a list comprehension. If you don't understand the rest of the code, how have you been learning?
The rest I understand. Thanks. Will look into list comprehensions.