• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
狼与狼
博客园 | 首页 | 新随笔 | 新文章 | 联系 | 订阅 订阅 | 管理

2020年3月17日

python(二十六) 缓存结果 lru cache
摘要: from functools import lru_cache class Solution: @lru_cache(None) def climbStairs(self,n): if n == 1: return 1 elif n == 2: return 2 else: return self. 阅读全文
posted @ 2020-03-17 13:36 狼与狼 阅读(710) 评论(0) 推荐(0)
 
python(二十五) 字典排序 OrderedDict
摘要: 为了控制一个字典中元素的顺序,可以使用 collections 模块中的 OrderedDict 类。 在迭代操作的时候,它会保持元素被插入时的顺序。 from collections import OrderedDict d = OrderedDict() d['foo'] = 1 d['bar' 阅读全文
posted @ 2020-03-17 11:09 狼与狼 阅读(289) 评论(0) 推荐(0)
 
python(二十四) 字典的一个键映射多个值 defaultdict
摘要: 使用 collections 模块中的 defaultdict 来构造这样的字典 defaultdict的一个特征是它会自动初始化每个key刚开始对应的值 from collections import defaultdict d = defaultdict(list) d['a'].append( 阅读全文
posted @ 2020-03-17 10:38 狼与狼 阅读(121) 评论(0) 推荐(0)
 
 

公告


博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3