Sometimes, while working with Python list, we can have a problem in which we have to transform the list elements to string. This is easier in case of integral list, as they can be joined easily with
join(), and their contents can be displayed. But the case with floats is different, there are additional undesired spaces among it’s values that can cause it’s unsuccess. Let’s discuss a ways in which this error situation can be handled.
Method #1 : Using list comprehension +
join() + str()
This task can be performed using combination of above functions. In this, we firstly convert each element of list i.e float point number to string and then join the resultant strings using the
The original list is : [5.8, 9.6, 10.2, 45.3, 6.0] Conversion of float list to string : 5.8 9.6 10.2 45.3 6.0
Method #2 : Using
join() + map() + str()
The root method is similar by using the combination of
join() + str(), but important function which helps to perform this task is
map(). This first converts each element to string and then constructs the master string.
The original list is : [5.8, 9.6, 10.2, 45.3, 6.0] Conversion using join + str : [ 5 . 8, 9 . 6, 1 0 . 2, 4 5 . 3, 6 . 0 ] Conversion using join + str + map : 5.8 9.6 10.2 45.3 6.0
- Convert String float to float list in Python
- Python | Min/Max value in float string list
- Python - Summation of float string list
- Python - Filter float strings from String list
- Python | Dictionary to list of tuple conversion
- Python | Decimal to binary list conversion
- Python | List of tuples to dictionary conversion
- Python - Convert Float to digit list
- Python | Ways to sort list of float values
- Python | Check for float string
- Python | Convert List of String List to String List
- Python | Convert mixed data types tuple list to string list
- Python | Convert list of string to list of list
- Python | Convert list of numerical string to list of Integers
- Python | Convert list of string into sorted list of integer
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.