python - Perform check on lists -
i have 2 lists:
main_voltages = [5.5, 15.7, 28.5] limit_list = [[5,10], [15,20], [25,30]]
i have perform check see if 5.5 in range of 5 10, if 15.7 in range of 15 20 , 28.5 in range of 25 30. how should make happen without hardcoding anything? ponder lot on functions couldn't exact way it.
this 1 way using zip()
:
>>> main_voltages = [5.5, 15.7, 28.5] >>> limit_list = [[5,10], [15,20], [25,30]] >>> result = [b[0] <= <= b[1] (a, b) in zip(main_voltages, limit_list)] >>> result [true, true, true]
or @ovgolovin pointed out, can unpack elements in limit_list
, do:
result = [a <= value <= b (value, (a, b)) in zip(main_voltages, limit_list)]
Comments
Post a Comment