Python Forum
adding elements to a list that are more than a specific number - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: adding elements to a list that are more than a specific number (/thread-25099.html)



adding elements to a list that are more than a specific number - Olavv - Mar-19-2020

How do I add elements from a list to another list that are more than a specific number?

I've tried this:
list1=[2, 5, 3]
list2=[]
if number in list1 > 3:
list2.append(number)

Why does this not work, and how can I change it?


RE: adding elements to a list that are more than a specific number - perfringo - Mar-19-2020

To iterate over items use for-loop and then use if-comparison to check value.


RE: adding elements to a list that are more than a specific number - Olavv - Mar-19-2020

(Mar-19-2020, 03:35 PM)perfringo Wrote: To iterate over items use for-loop and then use if-comparison to check value.
thank you