Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
More List Stuff
#1
How would I do this?
data = [1,3,6,7,10]
value = 5

Lower = ["""List of Numbers in data list lower than value(5)"""]
Higher = ["""List of Numbers in data list higher than value(5)"""]
Equal = ["""List of Numbers in data list equal to value(5)"""]
Reply
#2
What would be your guess?
ask yourself:
  • How do I access each element of the list?
  • Is that element < 5
  • or is that element > 5
  • or is that element == 5
Reply
#3

  1. You need operators: < > ==
  2. You need to iterate over the list and do the comparison with the operators inside the loop.
  3. If the condition is True, add the element to a new list
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#4
sorry for not saying this, I fixed the problem right after posting
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Run the code for some stuff it does not return me why Anldra12 3 2,797 Apr-19-2021, 02:01 PM
Last Post: Anldra12
  Unable to print stuff from while loop Nick1507 4 2,275 Sep-17-2020, 02:26 PM
Last Post: Nick1507
  How Do I Install Stuff for Python? CopBlaster 6 3,131 May-08-2020, 12:27 PM
Last Post: hussainmujtaba
  Learning to have Class and doing stuff with it... bako 2 1,955 Apr-29-2020, 05:07 PM
Last Post: bako
  [split] Automate the boring stuff, inserting commas in list srikanth 1 2,077 Jul-02-2019, 02:29 PM
Last Post: metulburr
  Automate the boring stuff : the tic tac toe game DJ_Qu 7 6,578 Apr-24-2019, 12:22 PM
Last Post: ichabod801
  Automate the boring stuff, inserting commas in list DJ_Qu 3 4,654 Apr-21-2019, 03:52 PM
Last Post: perfringo
  Need help importing stuff that python says it cant open Tiaan 2 2,804 Nov-30-2017, 09:54 PM
Last Post: Tiaan

Forum Jump:

User Panel Messages

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