I am reading from an excel file and require the generation of a list to pull from where it has every integer in a range to the number read as well as a specific decimal between each integer.
For instance, if I read that I require 2.3 units of x, then I would like to generate a list in range 0 to 2.3 that has [0, 0.3, 1.0, 1.3, 2.0, 2.3].
I have thought about adding two lists together:
Units = 3.3
ListIntegers = list(range(math.ceil(Units)))
ListFloats = list(range()) # Here I would need to create the 0.3, 1.3, 2.3, and 3.3
FinalList = ListIntegers + ListFloats
FinalList.sort() # This will put my list back in numerical order
- How would I create that list of specific float values?
- Is there a better way to do this?
>Solution :
How’s this?:
import math
Units = 5.8
addition = float("0." + str(Units).split(".")[1])
intList = list(range(math.ceil(Units)))
finalList = intList + [x+addition for x in intList]
finalList.sort()
print(finalList)
Output:
[0, 0.8, 1, 1.8, 2, 2.8, 3, 3.8, 4, 4.8, 5, 5.8]