string compreension code example
Example 1: python list comprehension
nums = [3578, 6859, 35689, 268]
half_of_nums = [x/2 for x in nums]
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)