Explain for loop used inside list

array=[10,9]
a=[item for item in array]
print(a)

In the above code how the second line of code is working?

1 Like
a = [item for item in array]

is roughly equivalent to:

a = []
for item in array:
  a.append(item)
1 Like

it works same as adding new elements to a empty list by using append() method…like this:-

array=[10,9]
a=[]
for item in array:
 a.append(item)
print(a)