摘要: 来自:https://www.cnblogs.com/Lambda721/p/6128351.html map()是 Python 内置的高阶函数,它接收一个函数 f 和一个 list,并通过把函数 f 依次作用在 list 的每个元素上,得到一个新的 list 并返回。 例如,对于list [1, 阅读全文
posted @ 2019-05-20 14:52 logo_mm 阅读(379) 评论(0) 推荐(0) 编辑
摘要: 第一种,使用压缩器:>>> m = {'a': 1, 'b': 2, 'c': 3, 'd': 4}>>> m.items()[('a', 1), ('c', 3), ('b', 2), ('d', 4)]>>> zip(m.values(), m.keys())[(1, 'a'), (3, 'c' 阅读全文
posted @ 2019-05-20 14:50 logo_mm 阅读(6251) 评论(0) 推荐(1) 编辑
摘要: 在java中,打乱list使用collections.shuffle()方法来实现的, python中要利用random模块中的shuffle方法 import random x = [i for i in range(5)] print(x) random.shuffle(x) print(x) 阅读全文
posted @ 2019-05-20 14:47 logo_mm 阅读(4220) 评论(0) 推荐(0) 编辑
摘要: 反转list一共有3中方法 a=[1,2,3,4,5] 1、list(reversed(a)); 2、sorted(a,revers=true) 3、a[: : -1] 其中[: : -1]代表从后向前取值,每次步进值为1,a【3: : -1】=[4,3,2,1] 代表从第3个坐标往前反转顺序输出, 阅读全文
posted @ 2019-05-20 14:38 logo_mm 阅读(4081) 评论(0) 推荐(0) 编辑
摘要: python遍历字典一共有四种方式 D={‘a’:1,‘b’:2,’b‘:3,’d‘:4} 1. 遍历key值 for key in a: pritn(key+':'+a[key]) for key in a.keys(): print(key+':'+a[key]) 2.遍历value值 for 阅读全文
posted @ 2019-05-20 14:30 logo_mm 阅读(3845) 评论(0) 推荐(0) 编辑