array=[10,9]
a=[item for item in array]
print(a)
In the above code how the second line of code is working?
array=[10,9]
a=[item for item in array]
print(a)
In the above code how the second line of code is working?
a = [item for item in array]
is roughly equivalent to:
a = []
for item in array:
a.append(item)
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)