使用列表推导式生成包含10个数字5的列表,语句可以写为_______________。
A. [5 for i in range(11)]
B. 5 for i in range(11)
C. [5 for i in range(10)]
D. 5 for i in range(10)
查看答案
已知列表 aList = [-1, -4, 6, 7.5, -2.3, 9, -11],则表达式[i for i in aList if i>0]的值为( )
A. [6, 9]
B. [7.5, 6, 9]
C. [6, 7.5, 9]
D. [9, 6, 7.5]
以下这段代码,转换成列表推导式,最合适的是( )。 squared = [] for x in range(10): squared.append(x**2)
A. squared = [x**2 for x in range(10)]
B. squared = [x for x**2 in range(10)]
C. squared = [x for x in range(10)]
D. squared = [xfor x in range(10)**2 ]
x = [ i for i in range(0, 10, 3) if i % 2==0],则x为( )。
A. [0, 6]
B. [6]
C. [6,]
D. [4,6]
表达式[x for x in [1,2,3,4,5] if x < 3]的值为( )。
A. [1,2,3]
B. [1]
C. [1,2]
D. [0,1,2]