-2

prices = [ .75, 2.25, 1.50, 3.0, 2.5, .50, .90, .85 3.5] What's the simplest way to return values >= 2 from the list.

I seen some code in Github and google but I can't get to work. I'm learning how to code in python 3.

prices = [.75, 2.25, 1.50, 3.0, 2.5, .50, .90, .85 3.5]
prince = sorted(i for i in j if i >= 2)
print(j2)

I expect this result [2.25, 2.5, 3.0, 3.5]

Masoud
  • 1,270
  • 7
  • 12
Jose
  • 1
  • 1
  • In python, the easiest way to filter lists is using list comprehensions, have you given it a try? There are plenty of related questions... – yatu Jul 08 '19 at 13:37

1 Answers1

0
prices = [.75, 2.25, 1.50, 3.0, 2.5, .50, .90, .85, 3.5]
prince = [item for item in prices if item => 2]
print (sorted(prince))

output:

[2.25, 2.5, 3.0, 3.5]
ncica
  • 7,015
  • 1
  • 15
  • 37