Search code examples
pythonlist-comprehension

How can I replace map() function with list comprehension or for loop?


How can I write this code without using map()

k1=list(map(float,lines[1].split(", ")[1:]))

Solution

  • You want to call float() function over every element of lines[1].split(", ")[1:]

    k1 = [float(x) for x in lines[1].split(", ")[1:]]