import timeit
print timeit.timeit('list(s)', 's=set(x for x in xrange(1000))')
# 23.952975494633154
print timeit.timeit("""li=[]
for x in s: li.append(x)""", 's=set(x for x in xrange(1000))')
# 189.3826994248866
list1 = []
size = 1
option = "Y"
for x in range(size):
ele = input("Enter Element For List One : ")
list1.append(ele)
while(option == "Y"):
option = input("\n***Add More Element Press Y ***: ")
if(option=="Y"):
size = size + 1
for x in range(size):
ele = input("Enter Element For List Element : ")
list1.append(ele)
size = 1
else:
break;
print(list1)
例如:
list1 = [] # Store Array Element
size = 1 # Rune at One Time
option = "Y" # Take User Choice
实施方法:
对于大小变量范围内的循环,由于 size = 1,循环只运行一次
使用 While 循环
如果用户想要添加“ Y”else“ N”,则接受他们的输入
在 while 循环中,如果选项是“ Y”,则使用 if else 语句
增加大小,有助于运行2时间数组,因为 size = size + 1
在一定范围内运行另一个 for 循环