-6

I have a list which has a range of numbers from 0 to 1:

[0.01,0.1,0.4,0.034,0.6,0.7,0.9,1]

How would I be able to edit the list so all the numbers from 0-0.5 to 0.4 and change all the numbers from 0.6-1 to 0.7, so the list becomes:

[0.4,0.40.40.4,0.7,0.7,0.7,0.7]

confindencenumbers = [(x=0.4) for x in confindencenumbers if x < 0.4]
confindencenumbers = [(x=0.7} for x in confindencenumbers if x > 0.5]
jamylak
  • 128,818
  • 30
  • 231
  • 230
miik
  • 663
  • 1
  • 8
  • 23
  • Really, there has to be some restriction you are not telling us, else it would be too trivial. – Cthulhu May 05 '13 at 09:19
  • 3
    I've [already told you](http://stackoverflow.com/questions/16163394/turning-a-list-into-a-tuple-python#comment23098912_16163394) to research, or try something yourself, before you ask. This is a very simple problem. – Volatility May 05 '13 at 09:21
  • That's [not a valid list comprehension](http://carlgroner.me/Python/2011/11/09/An-Introduction-to-List-Comprehensions-in-Python.html) – Volatility May 05 '13 at 09:27
  • 1
    Thats why I need help – miik May 05 '13 at 09:28
  • Possible dupe of http://stackoverflow.com/questions/4406389/if-else-in-a-list-comprehension – TerryA May 05 '13 at 09:30
  • Downvoted. Lack of research in this as well as past questions of the OP. – DhruvPathak May 05 '13 at 09:33

2 Answers2

3
>>> l = [0.01, 0.1, 0.4, 0.034, 0.6, 0.7, 0.9, 1]
>>> [0.4 if (0. < f < 0.5) else 0.7 for f in l]
[0.4, 0.4, 0.4, 0.4, 0.7, 0.7, 0.7, 0.7]
icecrime
  • 74,451
  • 13
  • 99
  • 111
0
[0.4 if 0 <= x <= 0.5 else 0.7 if 0.6 <= x <= 1 else DEFAULT_VAL for x in L]
jamylak
  • 128,818
  • 30
  • 231
  • 230