Sometimes, while working with Python list we can have a problem in which we require to populate the list in a range of decimal. Integral ranges are easier to handle using inbuilt constructs, but having a decimal value to provide to range value doesn’t work. Let’s discuss a way in which this problem can be solved.
Method : Using list comprehension
One way to solve this problem is by using the list comprehension which can solve this problem in easier way by iterating the list and multiplying the range element to the index of element.
The list after decimal range value initialization : [5.0, 5.4, 5.8, 6.2, 6.6]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Program to make Indian Flag in Python | Step by Step
- Django settings file - step by step Explanation
- Python - Step Frequency of elements in List
- matplotlib.axes.Axes.step() in Python
- bokeh.plotting.figure.step() function in Python
- matplotlib.pyplot.step() function in Python
- Python | Decimal to binary list conversion
- How to approach a Machine Learning project : A step-wise guidance
- PyQt5 QSpinBox - Setting single step size
- PyQt5 QSpinBox - Accessing single step size
- PyQt5 QSpinBox - Setting step type
- PyQt5 QSpinBox - Accessing step type
- PyQt5 QSpinBox – Step up the value using stepUp method
- PyQt5 QSpinBox – Step down the value using stepDown method
- wxPython - Create Radio Box with two step creation
- PyQt5 QDoubleSpinBox - Setting Step Type Property
- PyQt5 QDoubleSpinBox - Getting Step Type Property
- wxPython - Two step creation wx.TreeCtrl
- PyQt5 QScrollBar –Setting Single Step
- PyQt5 QScrollBar – Getting Single Step
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.