[float(i) for i in lst]

to be precise, it creates a new list with float values. Unlike the map approach it will work in py3k.

Answer from SilentGhost on Stack Overflow
🌐
Finxter
blog.finxter.com › how-to-convert-a-string-list-to-a-float-list-in-python
How to Convert a String List to a Float List in Python – Be on the Right Side of Change
The most Pythonic way to convert a list of strings to a list of floats is to use the list comprehension floats = [float(x) for x in strings]. It iterates over all elements in the list and converts each list element x to a float value using the float(x) built-in function.
🌐
Reddit
reddit.com › r/learnpython › no way i am trying lets me convert string list into float list
r/learnpython on Reddit: No way i am trying lets me convert string list into float list
October 25, 2023 -

Not able to convert the "close_list" list into a float? list? I've tried a lot of ways that I see on the internet a lot that it's too much to put in here, and i am still getting an error of:" Exception has occurred: TypeError:list indices must be integers or slices, not float File "{filename}\import csv.py", line 25, in <module> diff = close_list[i] - price_compare TypeError: list indices must be integers or slices, not float ".

Am i missing anything that needs to be declared or imported, updated extensions? I am doing exactly what the internet says and even putting in "import numpy as np" and that's not working and am getting real disappointed. i have tried updating it and numpy is already up to date. How can i modify this so i can actually subtract price_compare from close_list[i].

import csv
import os
import sys
import numpy as np

close_list = ['0.0', '1.0', '2.5', '2.0']
len = len(close_list)
price_compare = [close_list[0]]
diff = 0.0
price=0
# [float(i) for i in value]
diff_close_list = []
for i in range(1,len):
i = float(i)
# price_compare = float(price_compare)
diff = close_list[i] - price_compare
price_compare = i
print(type(i))
print(i)
print(type(price_compare))
print(price_compare)
print(type(diff))
print(diff)

diff_close_list.append(diff)
# print(diff_close_list)

🌐
GeeksforGeeks
geeksforgeeks.org › python-convert-float-string-list-to-float-values
Convert Float String List to Float Values-Python - GeeksforGeeks
February 5, 2025 - For example, if the input is 45.67, the output should be [4, 5, 6, 7].Using string manipulationIn this method, the number is converted to a string and then each charac ... Sometimes, while working with Python list, we can have a problem in which we need to separate the float values from valid strings.
🌐
Scaler
scaler.com › home › topics › how to convert string to float in python?
Convert String to Float in Python - Scaler Topics
May 5, 2022 - For converting the list of strings ... have to iterate the string list and take the values one by one and then convert the string values to the floating values and then append all the float values to the floating value list...
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-string-float-to-float-list-in-python
Convert String Float to Float List in Python - GeeksforGeeks
July 12, 2025 - For example, s = '1.23 4.56 7.89' ... 4.56, 7.89]. By using split() on a string containing float numbers, we can break it into individual string elements and then apply map() to convert each element into a float....
🌐
FavTutor
favtutor.com › blogs › string-to-float-python
6 Ways to Convert String to Float in Python | FavTutor
August 31, 2021 - To convert this list of strings into floating-point values, you have to use for loop to iterate through each item of the list. Later, you can use the float() method to convert each item into float value and then append it to the list again.
🌐
w3resource
w3resource.com › python-exercises › basic › python-basic-1-exercise-140.php
Python: Convert all items in a given list to float values - w3resource
Write a Python program to map a list of numeric strings to floats and output the new list using the float() function.
Find elsewhere
🌐
Easy Tweaks
easytweaks.com › python-convert-list-float-numbers
Convert a list of strings to float numbers in Python?
Skip to content · BECOMING MORE EFFICIENT WITH TECH · HELPING TO REDUCE BUSY WORK SO YOU CAN FOCUS ON STUFF THAT MATTERS · Check out our latest posts: · How to change the default Email Account in Gmail and Outlook · How to fix Windows 11 Not detecting Bluetooth headset · How to fix Microsoft ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-convert-string-to-float
How to Convert String to Float in Python: Complete Guide with Examples | DigitalOcean
July 10, 2025 - Learn how to convert strings to floats in Python using float(). Includes syntax, examples, error handling tips, and real-world use cases for data parsing.
🌐
Delft Stack
delftstack.com › home › howto › python › convert list to float python
How to Convert List to Float in Python | Delft Stack
February 2, 2024 - We begin with the list lst, which contains string representations of numbers. The generator expression float(item) for item in lst iterates through each item in the list, converting them to their corresponding floating-point values.
🌐
Statistics Globe
statisticsglobe.com › home › python programming language for statistics & data science › convert list from character string to float in python (3 examples)
Convert List from Character String to Float in Python (3 Examples)
December 6, 2024 - ... As seen in the script above, there are three strings in list string_list. In this first example, we will use the map() function to iterate through string_list and replace the strings with float numbers, which results in a new list called ...
🌐
Jeremy Morgan
jeremymorgan.com › python › how-to-convert-a-string-to-a-float-in-python
How to Convert a String to a Float in Python
Here are a few examples: If you have a list of strings that need to be converted to floats, you can use the map() function to apply the float() function to each string in the list.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-ways-to-convert-array-of-strings-to-array-of-floats
Python | Ways to convert array of strings to array of floats - GeeksforGeeks
July 11, 2025 - Here is the approach to convert ... array to store the converted floats. Loop through each element of the input array and convert the current element to a float using the float() function....
🌐
Replit
replit.com › home › discover › how to convert a string to a float in python
How to convert a string to a float in Python
string_numbers = ["10.5", "20.3", "30.1", "40.9"] # Using map float_numbers_map = list(map(float, string_numbers)) # Using list comprehension float_numbers_comp = [float(num) for num in string_numbers] print(float_numbers_map)--OUTPUT--[10.5, 20.3, 30.1, 40.9] When you need to convert a whole list of strings, writing a loop for each item is inefficient. Python offers two elegant one-liners for this: the map() function and list comprehensions.
🌐
IONOS
ionos.com › digital guide › websites › web development › converting python strings to floats
How to convert Python strings to floats - IONOS
January 2, 2025 - That means de­vel­op­ers working ... to catch and react to errors is one way to do this. The float() function is a built-in Python method that converts strings to floats....
🌐
Python Forum
python-forum.io › thread-39390.html
convert string to float in list
HI Do anyone know how to convert element in the list to float, and write them into excel? My code will read a file and write it into excel, attached picture. But I wish to convert the red mark into float, else in excel it will occur exclamation mar...
🌐
Hostman
hostman.com › tutorials › how to convert string to float in python
Python: How to Convert String to Float
March 31, 2025 - Again we’ve our float_list here is populated from the string_list and the items are converted from strings to floats. Python type casting is a fundamental concept that involves converting one data type to another. It provides compatibility and flexibility for programmers in their code.
Price   $
Address   1999 Harrison St 1800 9079, 94612, Oakland
🌐
Python Guides
pythonguides.com › convert-string-to-float-in-python
Convert String With Comma To Float In Python: 3 Easy Methods
April 22, 2025 - Read How To Convert JSON String To Dictionary In Python · Python’s locale module provides tools for working with different regional formatting. This is an elegant solution if you’re dealing with numbers in specific locales. import locale def locale_comma_to_float(string_value): # Set US locale (for comma as thousand separator) locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') # Parse the string and convert to float return locale.atof(string_value) # Example usage try: price_string = "1,234.56" price_float = locale_comma_to_float(price_string) print(f"Original string: {price_string}") print(f"Converted float: {price_float}") except locale.Error: print("Locale not supported on this system.