home
Learn
screen_rotation
mylist = [100,200,300,400,500] newlist = [] for item in mylist: if item > 200: newlist.append(item) else: newlist.append(1000) print(newlist) # create a new list using comprehension mylist = [100,200,300,400,500] newlist = [item if item > 200 else 1000 for item in mylist] print(newlist)
Program Output
[1000, 1000, 300, 400, 500] [1000, 1000, 300, 400, 500]