1、统计元素的个数:
a = [1, 2, 3, 1, 1, 2]
dict = {}
for key in a:
dict[key] = dict.get(key,0) + 1
print(dict)
def  count(m):
for  i  in  a:
result = a.count(m)
print(result)
if  __name__ == "__main__":
count(1)
2、冒泡排序
def  bubble_sort(num):
for i in  range(len(num)-1):   #这个循环负责设置冒泡排序进行的次数,即循环的趟数
for  j in  range(len(num)-1-i):   #i的初始值为0,每次循环确定一个值,循环一次,减少一趟
if  num[j] > num[j+1]:
num[j],num[j+1] = num[j+1],num[j]
return  num
if  __name__ == "__main__":
num = [1,2,3,4,9,5,2,3,8]
print(bubble_sort(num))