摘要:
import re line = 'asdf fjdk; afed, fjek,asdf, foo' # 切割 print(re.split(r'[;,\s]\s*', line)) # ['asdf', 'fjdk', 'afed', 'fjek', 'asdf', 'foo'] # 分组替换 p 阅读全文
摘要:
# 链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 重复的 阅读全文
摘要:
# 命名元组 from collections import namedtuple subscriber = namedtuple(typename='Subscriber', field_names=['name', 'age']) sub = subscriber('lisi', 10) pri 阅读全文
摘要:
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 阅读全文
摘要:
from operator import itemgetter from itertools import groupby rows = [ {'address': '5412 N CLARK', 'date': '07/01/2012'}, {'address': '5148 N CLARK', 阅读全文
摘要:
from operator import itemgetter from operator import attrgetter rows = [ {'fname': 'Brian', 'lname': 'Jones', 'uid': 1003}, {'fname': 'David', 'lname' 阅读全文