-6

我有一个列表,其中包含从0到的数字范围1

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

我如何能够编辑列表,以便所有数字从0-0.5to0.4并将所有数字从0.6-1to更改0.7,所以列表变为:

[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]
4

2 回答 2

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]
于 2013-05-05T09:27:35.700 回答
0
[0.4 if 0 <= x <= 0.5 else 0.7 if 0.6 <= x <= 1 else DEFAULT_VAL for x in L]
于 2013-05-05T10:23:34.877 回答