Python Forum
unable to remove all elements from list based on a condition
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unable to remove all elements from list based on a condition
#4
A list comprehension would work well here
values = [6.2, 5.9, 4.8, 6.1, 6.1, 6.5, 5.9, 5.8, 6.2]
print([value for value in values if value > 6])
sg_python and Pedroski55 like this post
Reply


Messages In This Thread
RE: unable to remove all elements from list based on a condition - by deanhystad - Jan-27-2024, 04:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  remove duplicates from dicts with list values wardancer84 27 820 May-27-2024, 04:54 PM
Last Post: wardancer84
  How to remove some elements from an array in python? gohanhango 9 1,529 Nov-28-2023, 08:35 AM
Last Post: Gribouillis
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 552 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  Sent email based on if condition stewietopg 1 953 Mar-15-2023, 08:54 AM
Last Post: menator01
  Checking if a string contains all or any elements of a list k1llcod3 1 1,223 Jan-29-2023, 04:34 AM
Last Post: deanhystad
  create new column based on condition arvin 12 2,476 Dec-13-2022, 04:53 PM
Last Post: jefsummers
  Remove numbers from a list menator01 4 1,473 Nov-13-2022, 01:27 AM
Last Post: menator01
  How to assign a value to pandas dataframe column rows based on a condition klllmmm 0 907 Sep-08-2022, 06:32 AM
Last Post: klllmmm
  How to change the datatype of list elements? mHosseinDS86 9 2,130 Aug-24-2022, 05:26 PM
Last Post: deanhystad
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,368 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