[英]How do you round() a map function in python?
I am trying to do this,我正在努力做到这一点,
print(list(round(map(radius, cirumfrence), 1)))
but it comes up with this error:/但它出现了这个错误:/
print(list(round(map(radius, cirumfrence), 1)))
TypeError: type map doesn't define __round__ method
Anyone know what the problem is?有谁知道问题是什么? Thanks!谢谢!
Here is the whole code.这是整个代码。
cirumfrence = [2.7, 69, 7, 2]
radius = lambda circ: ((circ)/2*math.pi)
print(list(map(round(radius, cirumfrence))))
I would use a list comprehension:我会使用列表理解:
cirumfrence = [2.7, 69, 7, 2]
radius = lambda circ: ((circ)/2*math.pi)
new_lst = [round(radius(x),2) for x in cirumfrence]
Output: [4.24, 108.38, 11.0, 3.14]输出:[4.24, 108.38, 11.0, 3.14]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.