Ai
2 Star 1 Fork 1

望曦开源团队/Python案例合集

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
CountX.py 332 Bytes
Copy Edit Raw Blame History
NineSenz-九练 authored 2023-04-30 00:00 +08:00 . 计算元素在列表中出现的次数
# 定义一个列表,并计算某个元素在列表中出现的次数
lst = [8, 6, 8, 10, 8, 20, 10, 8, 8]
x = 8
def countX(lst, x):
count = 0
for ele in lst:
if (ele == x):
count = count + 1
return count
def countX2(lst, x):
return lst.count(x)
print(countX(lst, x))
print(countX2(lst, x))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wangxios/workspace_Python.git
git@gitee.com:wangxios/workspace_Python.git
wangxios
workspace_Python
Python案例合集
master

Search