上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 43 下一页
摘要: import re line = 'asdf fjdk; afed, fjek,asdf, foo' # 切割 print(re.split(r'[;,\s]\s*', line)) # ['asdf', 'fjdk', 'afed', 'fjek', 'asdf', 'foo'] # 分组替换 p 阅读全文
posted @ 2020-07-29 15:55 fly_bk 阅读(127) 评论(0) 推荐(0) 编辑
摘要: # 链map from collections import ChainMap a = {'x': 1, 'z': 3} b = {'y': 2, 'z': 4} c = ChainMap(a, b) print(c['x']) print(c['y']) print(c['z']) # 3 重复的 阅读全文
posted @ 2020-07-29 13:59 fly_bk 阅读(109) 评论(0) 推荐(0) 编辑
摘要: # 命名元组 from collections import namedtuple subscriber = namedtuple(typename='Subscriber', field_names=['name', 'age']) sub = subscriber('lisi', 10) pri 阅读全文
posted @ 2020-07-29 13:50 fly_bk 阅读(129) 评论(0) 推荐(0) 编辑
摘要: values = ['1', '2', '-3', '-', '4', 'N/A', '5'] def isNum(s): try: int(s) return True except: return False print(list(filter(lambda i: isNum(i), value 阅读全文
posted @ 2020-07-29 11:27 fly_bk 阅读(137) 评论(0) 推荐(0) 编辑
摘要: from operator import itemgetter from itertools import groupby rows = [ {'address': '5412 N CLARK', 'date': '07/01/2012'}, {'address': '5148 N CLARK', 阅读全文
posted @ 2020-07-29 10:55 fly_bk 阅读(173) 评论(0) 推荐(0) 编辑
摘要: from operator import itemgetter from operator import attrgetter rows = [ {'fname': 'Brian', 'lname': 'Jones', 'uid': 1003}, {'fname': 'David', 'lname' 阅读全文
posted @ 2020-07-29 10:28 fly_bk 阅读(176) 评论(0) 推荐(0) 编辑
摘要: https://python3-cookbook.readthedocs.io/zh_CN/latest 阅读全文
posted @ 2020-07-28 16:38 fly_bk 阅读(436) 评论(0) 推荐(0) 编辑
摘要: import numpy as np if __name__ == '__main__': print(np.__version__) vec = np.array([1, 2, 3]) print(vec) vec[0] = '111' print(vec) # [111 2 3] # vec[0 阅读全文
posted @ 2020-07-28 13:41 fly_bk 阅读(806) 评论(0) 推荐(0) 编辑
摘要: import math class Vector: """向量""" @classmethod def zero(cls, dim): """dim长度的0向量""" return cls([0] * dim) def __init__(self, lst): self._values = list 阅读全文
posted @ 2020-07-28 10:49 fly_bk 阅读(111) 评论(0) 推荐(0) 编辑
摘要: # 一个键对应多个值 defaultdict from collections import defaultdict # 参数是类型 d = defaultdict(list) d['a'].append(1) d['a'].append(2) d['b'].append(3) print(d) d 阅读全文
posted @ 2020-07-27 16:36 fly_bk 阅读(144) 评论(0) 推荐(0) 编辑
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 43 下一页