Python Forum
adding elements to a list that are more than a specific number
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
adding elements to a list that are more than a specific number
#1
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?
Reply
#2
To iterate over items use for-loop and then use if-comparison to check value.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  unable to remove all elements from list based on a condition sg_python 3 377 Jan-27-2024, 04:03 PM
Last Post: deanhystad
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 427 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  Delete strings from a list to create a new only number list Dvdscot 8 1,466 May-01-2023, 09:06 PM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,014 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  Checking if a string contains all or any elements of a list k1llcod3 1 1,023 Jan-29-2023, 04:34 AM
Last Post: deanhystad
  Adding values with reduce() function from the list of tuples kinimod 10 2,515 Jan-24-2023, 08:22 AM
Last Post: perfringo
  How to change the datatype of list elements? mHosseinDS86 9 1,910 Aug-24-2022, 05:26 PM
Last Post: deanhystad
  search a list or tuple for a specific type ot class Skaperen 8 1,854 Jul-22-2022, 10:29 PM
Last Post: Skaperen
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 4,763 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,013 May-17-2022, 11:38 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020