一、回文数
说明:类似与"aaabaaa","ababa"等对称字符
def is_huiwen(str):
b = len(a)
for i in a :
b -= 1
if i == a[b]:
continue
else:
return "no"
return "yes"
二、数组去重
说明:[1,2,3,4,5,1,7]存在一个1重复
lambda list : set(list)
b = {}; b.formkeys(list)
三、统计重复次数
说明:[1,1,1,1,4,5,6,7,8,]统计1出现的次数
def statistic(list):
dic_count = {}
dic_count.formkeys(list1, 0)
for i in list:
dic_count[i] += 1
return dic_count
四、冒泡排序
def bubble(list):
a = list[0]
for i in range(len(list)-1):
for l in range(len(list)-i-1):
if list[l] > list[l+1]:
list[l], list[l+1] = list[l+1], list[l]
return list
五、快速排序
def q_sort(list):
a = list[0]
left = q_sort([x for x in list[1:] if x < a ])
right = q_sort([x for x in list[1:] if x > a])
return left + [a] + right
网友评论