Python Forum
list of strings to list of float
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
list of strings to list of float
#2
For each line item eg. -48.9701217110874,5.67558617156734,0, you can use split() to turn it to a list. Then delete last item. Then use list comprehension to make a new list of floats.
line_item = "-48.9701217110874,5.67558617156734,0"
new_item = list(line_item.split(","))
del new_item[-1]
coordinate = [float(num) for num in new_item]
print(coordinate)
print(type(coordinate[1]))
Reply


Messages In This Thread
list of strings to list of float - by undoredo - Feb-17-2020, 09:00 PM
RE: list of strings to list of float - by michael1789 - Feb-17-2020, 11:40 PM
RE: list of strings to list of float - by undoredo - Feb-19-2020, 08:51 AM
RE: list of strings to list of float - by scidam - Feb-17-2020, 11:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to reverse a list and store in another list in python SuperNinja3I3 6 3,448 Aug-14-2022, 06:36 PM
Last Post: DeaD_EyE
Question Python - List - Int List sophi 8 2,725 Apr-21-2022, 07:55 PM
Last Post: sophi
  Removing all strings in a list that are of x length Bruizeh 5 3,315 Aug-27-2021, 03:11 AM
Last Post: naughtyCat
  Check if a list exists in given list of lists Daniel94 2 2,320 Apr-07-2020, 04:54 PM
Last Post: deanhystad
  Convert a list of integers to strings? Cornelis 3 2,343 Nov-15-2019, 12:13 PM
Last Post: perfringo
  arrays sum list unsupported operand type(s) for +=: 'int' and 'list' DariusCG 7 4,354 Oct-20-2019, 06:24 PM
Last Post: Larz60+
  have homework to add a list to a list using append. celtickodiak 2 2,084 Oct-11-2019, 12:35 PM
Last Post: ibreeden
  Search character from 2d list to 2d list AHK2019 3 2,555 Sep-25-2019, 08:14 PM
Last Post: ichabod801
  I donr know how to search from 2d list to 2d list AHK2019 1 1,800 Sep-25-2019, 01:59 AM
Last Post: ichabod801
  sort a list alphabeticaly without changing the original list Holmen 5 4,310 Jan-27-2019, 01:49 PM
Last Post: Holmen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020