首页 > 其他 > 详细

列表[1,2,3,4,5],请使用map()函数输出[1,4,9,16,25],并使用列表推导式提取出大于10的数,最终输出[16,25]

时间:2020-03-10 20:05:13      阅读:57      评论:0      收藏:0      [点我收藏+]

列表[1,2,3,4,5],请使用map()函数输出[1,4,9,16,25],并使用列表推导式提取出大于10的数,最终输出[16,25]

def f(x):
    return x**2
 
 
res = map(f, [1, 2, 3, 4, 5])
print([i for i in res if i > 10])

python中生成随机整数、随机小数、0—1之间小数方法

import random
import numpy as np
 
a = random.randint(10,20)
res = np.random.randn(5)
ret = random.random()
print("正整数:"+str(a))
print("5个随机小数:"+str(res))
print("0-1随机小数:"+str(ret))

 

本文首发于Python黑洞网,博客园同步跟新

 

 

列表[1,2,3,4,5],请使用map()函数输出[1,4,9,16,25],并使用列表推导式提取出大于10的数,最终输出[16,25]

原文:https://www.cnblogs.com/pythonzhilian/p/12458091.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!