python: collections counter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 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)] |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | 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 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | ''' 移除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(涂聚文)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
2010-06-08 ASP.NET 3.5(c#)区域化设置(LCID)
2009-06-08 C#2.0 数字“0”是有一道斜线,打印虚线,Pos打印