数组降维
123matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]][k for i in matrix for k in i]1, 2, 3, 4, 5, 6, 7, 8, 9][矩阵行列互转
123a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]re_a = list(zip(*a))1, 4, 7], [2, 5, 8], [3, 6, 9]][[字典的键、值互换
123456a = {'a': 1, 'b': 2, 'c': 3, 'd': 4}def reverse_dict(a):k = a.keys()v = a.values()new_dict = dict(zip(v, k))return new_dict合并一个list的相邻项
123a = [1, 2, 3, 4, 5, 6]list(zip( a[::2], a[1::2] ))1, 2), (3, 4), (5, 6)][(反转字符串
123a = 'python'a[::-1]'nohtyp'统计list中1的个数
|
|