Jan-27-2024, 10:15 AM
(This post was last modified: Jan-27-2024, 10:16 AM by Pedroski55.)
As Yoriz said, it is not good to remove items from a list while you are looping through it. Will cause problems!
Nor is it good to use the reserved word list as you did.
You could approach this from the other way round, instead of slicing out a copy, create a new list to start with and append:
Nor is it good to use the reserved word list as you did.
You could approach this from the other way round, instead of slicing out a copy, create a new list to start with and append:
mylist=[6.2,5.9,4.8,6.1,6.1,6.5,5.9,5.8,6.2] mynewlist = [] for a in mylist: if a>=6.0: mynewlist.append(a) print(mynewlist)
Output:[6.2, 6.1, 6.1, 6.5, 6.2]
I think it is a good idea to preserve the original list for later use perhaps.