python3

TypeError: float() argument must be a string or a number, not 'list' python

You can't call float on a list directly. You can use map to call float on each item in the list. Like so:
b = map(float, a[0].split(""))
In python 3.x
b = list(map(float, a[0].split("
")))
Or for more readability, use a list comprehension. Works for both python2 and python3:
b = [float(s) for s in a[0].split("*")]
But be sure the items after splitting are floatable

posted on 2019-08-27 15:17  JudeHey  阅读(209)  评论(0)    收藏  举报