List Comprehensions

#define a list named "numbers" with 7 values
numbers = [34.6, -203.4, 44.9, 68.3, -12.2, 44.6, 12.7]

#create a newlist using list comprehensions:
newlist = [int(x) for x in numbers if x > 0]

#printing newlist will only have positive numbers
print(newlist)

Leave a comment

Design a site like this with WordPress.com
Get started