将列表元素提升为幂 [英] Raising elements of a list to a power

查看:63
本文介绍了将列表元素提升为幂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将列表中的数字提高到一定程度?

How can I raise the numbers in list to a certain power?

推荐答案

使用列表理解:

def power(my_list):
    return [ x**3 for x in my_list ]

https://docs.python.org/3.4/tutorial/datastructures.html#list-comprehensions

这篇关于将列表元素提升为幂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆