Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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)
Source by google.github.io #
 
PREVIOUS NEXT
Tagged: #python #list #comprehension
ADD COMMENT
Topic
Name
4+4 =