摘要:Ref: Natural Language Toolkit Ref: n-grams in python, four, five, six grams? Ref: "Elegant n-gram generation in Python" Another method to output: 获取一段
阅读全文
摘要:Ref: Python Tips 1. *args and **kwargs 2. Debugging 3. Generators 4. Map, Filter and Reduce 5. set Data Structure 6. Ternary Operators 7. Decorators 8
阅读全文
摘要:参考:Python format 格式化函数 参考:python基础_格式化输出(%用法和format用法) # 保留小数点后两位 f'{3.1415926:.2f}' # 带符号保留小数点后两位 f'{3.1415926:+.2f}' f'{-1:+.2f}' # 不带小数 f'{2.71828:
阅读全文
摘要:itemgetter 用来获取数组中指定索引的元素 slice 用来为列表切片,也是获取指定索引的元素 and_ 相当于 a & b,用来求两个集合的交集 可以联合 reduce 实现多个集合交集的计算 or_ 相当于 a | b,用来求两个集合的交集 可以联合 reduce 实现多个集合并集的计算
阅读全文
摘要:参考:itertools模块 product 相当于返回两个集合中数据的所有组合可能 Examples from Eric Martin 例子2:二进制数三位数的所有可能 chain 就是合并成一个 iter accumulate 可以实现将可迭代对象进行累加的效果,形成一个新的可迭代对象
阅读全文
摘要:参考:4. Map, Filter and Reduce — Python Tips 0.1 documentation 参考:Python的functools.reduce用法 Map:映射,对于列表的每个元素进行相同的操作 filter:筛选,筛选列表中满足某一条件的所有元素 reduce:归纳
阅读全文
摘要:可以定义一个字典,可以添加默认值,int 为 0,list 为 [],set 为 {} int:默认值为 0 list,默认值为空列表,也可以用 append set:默认值为空集合
阅读全文
摘要:namedtuple 能够实现类似类的效果,tuple 的元素可以通过属性的形式返回,如下所示: 因此若是想要让函数返回属性的效果,只需让函数的返回值是 namedtuple 即可,如下所示
阅读全文
摘要:参考:获取python的list中含有重复值的index方法_python_脚本之家 核心思想:建立字典,遍历列表,把列表中每个元素和其索引添加到字典里面
阅读全文
摘要:参考:Equivalent of Numpy.argsort() in basic python? - Stack Overflow 通过 enumerate 实现
阅读全文
摘要:参考:Kaggle Pandas Tutorial Part 1 参考:Kaggle Pandas Tutorial Part 2 参考:Pandas速查手册 参考:pandas 官方 API pandas.Series:单列的 pandas.DataFrame:数据表格 ref: Pandas:
阅读全文
摘要:Reference: [1] Python all() - Python Standard Library [2] Python any() - Python Standard Library all() and any() 函数主要用于需要判断某个数组是不是都满足了某种条件,设置一个跟数组一样的
阅读全文
摘要:Recently I am doing the assignment of COMP9021. It is too difficult and it is about the Knight and Knave. While I tried to finish this assignment, how
阅读全文