'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 1:[1]
You want to call float() function over every element of lines[1].split(", ")[1:]
k1 = [float(x) for x in lines[1].split(", ")[1:]]
Solution 2:[2]
You can use a for loop:
k1 = []
for x in lines[1].split(', ')[1:]:
k1.append(float(x))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | OneCricketeer |
| Solution 2 | BrokenBenchmark |
