python list comprehension tutorial example explained
#python #list #comprehension
list comprehension = a way to create a new list with less syntax
can mimic certain lambda functions, easier to read
list = [expression for item in iterable]
list = [expression for item in iterable if conditional]
list = [expression if/else for item in iterable]
--------------------------------------------------------------
squares = [] # create an empty list
for i in range(1,11): # create a for loop
squares.append(i * i) # define what each loop iteration should do
print(squares)
create a list AND defines what each loop iteration should do
squares = [i * i for i in range(1,11)]
print(squares)
--------------------------------------------------------------
On this page of the site you can watch the video online Python list comprehension 📰 with a duration of hours minute second in good quality, which was uploaded by the user Bro Code 25 January 2021, share the link with friends and acquaintances, this video has already been watched 34,413 times on youtube and it was liked by 1.6 thousand viewers. Enjoy your viewing!