【发布时间】:2021-05-16 02:01:30
【问题描述】:
我很难理解为什么我在运行以下代码时收到错误 TypeError: 'float' object is not iterable:
traces = [[ -122.29175806045532, 37.809512710254495 ],
[ -122.29154348373412, 37.810233196634634 ],
[ -122.29129672050475, 37.810996056903875 ],
[ -122.29098558425902, 37.811801289748544 ],
[ -122.29082465171813, 37.81219966485621 ],
[ -122.2902774810791, 37.812106428321556 ],
[ -122.28985905647279, 37.81201319166914 ] ]
for trace in traces:
s = ";".join(map(lambda y: ",".join(str(x) for x in y), trace))
【问题讨论】:
-
也许把你的oneliner写成传统的
for循环,你会看到的。 -
trace类似于[1.2, 1.3],所以y类似于1.2。您正在迭代y(str(x) for x in y),这没有意义。
标签: python loops for-loop typeerror