摘要: 1.通过关键字dict和关键字参数创建 >>> dic = dict(spam = 1, egg = 2, bar =3) >>> dic {'bar': 3, 'egg': 2, 'spam': 1} 2.通过二元组列表创建 >>> list = [('spam', 1), ('egg', 2), ('bar', 3)] >>> dic = dict(list) >>> dic {'bar'. 阅读全文
posted @ 2017-12-19 14:28 yooma 阅读(23085) 评论(0) 推荐(0)
摘要: >>> l1=[1,2,3,4,5,6]>>> l2=[4,5,6,7,8,9]>>> >>> >>> >>> {k:v for k,v in zip(l1,l2)}{1: 4, 2: 5, 3: 6, 4: 7, 5: 8, 6: 9}>>> >>> >>> >>> x = {1: 4, 2: 5 阅读全文
posted @ 2017-12-19 14:22 yooma 阅读(17558) 评论(0) 推荐(1)
摘要: # 正则将匹配到的两个字段,都替换成某个值import re s0 = 'BOY and GIRL' s1 = re.sub(r'BOY|GIRL', 'HUMAN', s0) print s1 # HUMAN and HUMAN 阅读全文
posted @ 2017-12-19 14:15 yooma 阅读(3348) 评论(0) 推荐(0)