创建两个包含10个实例的列表,然后创建包含x和y 10次的第三个列表

Ros*_*oss -3 python variables list

我有一个问题,但我真的不明白他们要求我做什么.他们给我的问题是:

这个练习的目标是创建两个列表称为x_listy_list区,其中包含变量的10个实例x,并y分别.您还需要创建一个名为列表big_list,其中包含变量xy,每组10次,通过连接你已经创建了两个列表.

代码是:

x = object()
y = object()

# change this code
x_list = [x]
y_list = [y]
big_list = x_list + y_list

print "x_list contains %d objects" % len(x_list)
print "y_list contains %d objects" % len(y_list)
print "big_list contains %d objects" % len(big_list)

# testing code
if x_list.count(x) == 10 and y_list.count(y) == 10:
    print "Almost there..."
if big_list.count(x) == 10 and big_list.count(y) == 10:
    print "Great!"
Run Code Online (Sandbox Code Playgroud)

结果是:

x_list contains 10 objects
y_list contains 10 objects
big_list contains 20 objects

Almost there...
Great!
Run Code Online (Sandbox Code Playgroud)

Ter*_*ryA 5

要获得多个实例,只需将列表相乘:

x_list = [x]*10
y_list = [y]*10
Run Code Online (Sandbox Code Playgroud)