1、有一个列表,去除其中的重复项
a = [1, 3, 12, 7, 3, 1, 5, 8, 12, 5, 21, 44] new_a = list(set(a))
2、实现I love China 输出 China love I
def test_reverse(str1): list1 = str1.split(' ') list2 = list1[::-1] str2 = ' '.join(list2) return str2
3、冒泡排序
def bubble_sort(arr): n = len(arr) for j in range(n): for i in range(0, n - j - 1): if arr[i] > arr[i + 1]: arr[i], arr[i + 1] = arr[i + 1], arr[i] return arr
4、选择排序
def sort(arr): n = len(arr) for j in range(n): min_index = j for i in range(j+1, n, 1): if (arr[i] < arr[min_index]): min_index = i arr[j], arr[min_index] = arr[min_index], arr[j] return arr
5、用代码实现斐波那契数列
比如:1,1,2,3,5,8,13,21,34....
def fib_test(n): if n == 0 or n == 1: return n return fib_test(n-1) + fib_test(n-2)
6、判断一个数字是否是回文数
12321是回文数,12345不是回文数
def is_palindrome(num): num1 = str(num)[::-1] return num == int(num1)
标签:index,arr,return,min,python,range,小题目,def From: https://www.cnblogs.com/daydayup-lin/p/17198394.html