开发者社区> 问答> 正文

将fahreneit转换为Celsius会不断得到0的列表?

我正在尝试使用地图将摄氏温度列表转换为华氏温度,但我一直在获取0的空列表

def Celsius(x):
    return ((x - 32) * (5 / 9))


flist=list(range(40,100,10))
result = map(Celsius, flist)
print(list(result))

问题来源:stackoverflow

展开
收起
is大龙 2020-03-24 12:24:59 585 0
1 条回答
写回答
取消 提交回答
  • Pythonlist不支持这类操作。看到下面的简单示例,您将得到相同的结果:

    l = [1,2,3]
    l - 3
    

    几种解决方案:

    • Iterating the items of the list and calling the function for each:

      result=[Celsius(item) for item in flist]
      
    • Use ` map ` function:

      result = map(Celsius, flist)
      
    • If using numpy arrays then it supports these kind of operations:

      flist = np.array(flist)
      

      Celsius(flist)

    回答来源:stackoverflow

    2020-03-24 12:25:06
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载