list comprehension list in list code example
Example 1: list comprehensions
h_letters = [ letter for letter in 'human' ]
print( h_letters)
Example 2: python list comprehension
lst=[1,2,3,4,5]
lst2=[item for item in lst if <condition>]
# generates a list based on another list and an if statement. the code above is a replacement for:
lst=[1,2,3,4,5]
lst2=[]
for item in lst:
if <condition>:
lst2.append(item)