python: collections counter
FF=[[]]
for i in range(0,10):
kk = []
for k in range(0,10):
if(k==0):
kk.append(i)
else:
kk.append(k)
#print(kk)
FF.insert(i,kk)
print(FF)
# 打印列表
for row in FF:
for col in row:
print(col, end=" ")
print()
rows, cols = (5, 5)
arr = [[0]*cols]*rows
N = 5
arr = [0 for i in range(N)]
entrance_fee = [70, 80, 105, 110, 120, 125]
entrance_fee = entrance_fee + [0]
index =6
k = 0
while k<6 and index==6: # 因为这里index 是6 ,初始值必须是6
if 115<entrance_fee[k]:
index=k
k=k+1
print("index",index)
for k in range(6,index,-1):
entrance_fee[k]=entrance_fee[k-1]
entrance_fee[index]=115
print(entrance_fee)
result = ['Pass', 'Fail', 'Pass', 'Pass', 'Pass', 'Pass', 'Pass', 'Pass', 'Pass', 'Pass']
p=Counter(result) # 引用库 from collections import Counter
#print(dict(p)) #分类计数的结果
#print(p['Pass'])
if(p["Pass"]>=5):
print("S/he gets the certificate of completion.")
else:
print("S/he needs to pass more tests.")
while True:
num=0
P=0
result = []
#也可以用while 或for
s=0
while num<10 and P<=5: #当达到5时,就可以确定极格,不用再计数了
s=num+1
test=input(str(s)+":input Pass/Fail")
result.append(test.strip()) #去除两头空格
num+=1
'''
for k in range(0,10):
num=k+1
test = input(str(num)+":input Pass/Fail")
result.append(test.strip()) # 去除两头空格
'''
print("score",result)
for k in range(0, 10):
if result[k] == "Pass":
P = P + 1
if P == 5: #5极格了,就结束
break
if P >= 5:
print("S/he gets the certificate of completion.")
else:
print("S/he needs to pass more tests.")
yn=input("Whether to continue testing(Y/N)?")
if(yn=='Y' or yn=='y'):
continue
else:
break
''' 移除Paul 这个值 index 1
eca=["Tony","Paul","Kelly","Wendy","Jack"]
for k in range(1,4): # index 1
eca[k]=eca[k+1]
eca[4]="" #len-1
'''
while True:
damin=input("please enter dmain name:")
tld=""
N=len(damin)
dot=-1
for i in range(0,N):
if damin[i]=='.':
dot=i
if dot!=-1:
for i in range(dot+1,N):
tld=tld+damin[i]
print(tld)
else:
print("Not a proper domain name")
yn=input("Y/N?")
if(yn=='Y' or yn=='y'):
continue
else:
break
word='Work Hard'
sub_word=word[5:7]
print(sub_word)
#移动位置 要移的index 指定的位置index 1
show=['2A','3B','1C','4E','5A']
temp=show[3]
for k in range(3,1,-1):
show[k]=show[k-1]
show[1]=temp
print(show)
show=['2A','3B','1C','4E','5A']
temp=show[3]
for k in range(3,0,-1):
show[k]=show[k-1]
show[0]=temp
print(show)
#移除
wait = [3001, 4001, 5001, 2001, 2002, 3002, 2003, 4002, 2004, 2005]
delindex=2
for k in range(delindex,len(wait)-1):
wait[k]=wait[k+1]
wait[len(wait)-1]=0
print(wait)
#添加一个 添加位置 index 4
wait=[3001,4001,5001,2001,2002,3002,2003,4002,2004,2005]
wait=wait+[0]
for k in range(len(wait)-1,4,-1):
wait[k]=wait[k-1]
wait[4]=9001
print(wait)
print('*********')
eca=["Tony","Paul","Kelly","Wendy","Jack"]
eca =eca+['']
nn=len(eca);
for k in range(nn-1,3,-1):
eca[k]=eca[k-1]
eca[3]="viky"
print(eca)
entrance_fee = [70, 80, 105, 110, 120, 125]
entrance_fee = entrance_fee + [0]
index = 6
k = 0
'''
while k < 6 and index == 6: # 因为这是6,初始值必须是6
if 115 < entrance_fee[k]:
index = k
k = k + 1
'''
''''''
for f in range(0,6):
if 115>entrance_fee[f]:
index=f
print("index",index)
for k in range(6,index,-1):
entrance_fee[k]=entrance_fee[k-1]
print(entrance_fee[k])
entrance_fee[index]=115
print(entrance_fee)
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
浙公网安备 33010602011771号