`
wanguan2000
  • 浏览: 68543 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

"To sort a dictionary" (Python recipe)

 
阅读更多

## {{{ http://code.activestate.com/recipes/52306/ (r2)
# (IMHO) the simplest approach:
def sortedDictValues1(adict):
    items = adict.items()
    items.sort()
    return [value for key, value in items]

# an alternative implementation, which
# happens to run a bit faster for large
# dictionaries on my machine:
def sortedDictValues2(adict):
    keys = adict.keys()
    keys.sort()
    return [dict[key] for key in keys]

# a further slight speed-up on my box
# is to map a bound-method:
def sortedDictValues3(adict):
    keys = adict.keys()
    keys.sort()
    return map(adict.get, keys)
## end of http://code.activestate.com/recipes/52306/ }}}

分享到:
评论

相关推荐

    Python Cookbook, 2nd Edition

    Using a Dictionary to Dispatch Methods or Functions Recipe 4.17. Finding Unions and Intersections of Dictionaries Recipe 4.18. Collecting a Bunch of Named Items Recipe 4.19. Assigning and ...

    Python Testing Cookbook (第1版)

    This cookbook is written as a collection of code recipes containing step-by-step directions on how to install or build different types of Python test tools to solve different problems. Each recipe ...

    Python GUI Programming Cookbook.pdf

    Throughout the book, you will develop an entire GUI application, building recipe upon recipe, connecting the GUI to a database. In the later chapters, you will explore additional Python GUI frameworks...

    Python库 | recipe_scrapers-10.1.0.tar.gz

    "Python库 | recipe_scrapers-10.1.0.tar.gz" 是一个针对Python开发者的资源,它包含了名为 `recipe_scrapers` 的库,版本号为10.1.0。这个库是一个用于抓取食谱网站数据的工具,帮助开发者轻松地从互联网上获取食谱...

    Python库 | git-recipe-0.2.7.tar.gz

    标题中的“Python库 | git-recipe-0.2.7.tar.gz”指的是一个与Python相关的库,名为“git-recipe”,版本号为0.2.7,并且它被压缩成一个tar.gz文件进行分发。这种格式是Unix/Linux环境中常用的压缩方式,用于归档和...

    Python库 | djc.recipe2-2.1.zip

    资源分类:Python库 所属语言:Python 资源全名:djc.recipe2-2.1.zip 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    Python库 | as.recipe.filetemplate-2.2.0-py2.7.egg

    本文将深入探讨`as.recipe.filetemplate-2.2.0-py2.7.egg`这个特定的Python库,它主要用于构建和管理文件模板。这个库的名字表明它是`as`组织的一部分,并且是`recipe`系列的一个组件,专注于处理`filetemplate`。...

    Python库 | recipe-0.30.1.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:recipe-0.30.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    Python Cookbook, 2nd Edition (epub 格式)

    Each chapter is devoted to a particular kind of recipe, such as algorithms, text processing, databases, and so on. The 1st edition had 17 chapters. There have been improvements to Python, both ...

    Python库 | appfy.recipe.gae-0.7.1.zip

    标题中的"Python库 | appfy.recipe.gae-0.7.1.zip"指的是一个特定版本(0.7.1)的Python库,名为`appfy.recipe.gae`。这个库是专门为Google App Engine (GAE)开发的,GAE是一个云服务平台,允许开发者构建和运行Web...

    Python库 | recipe_searchers-0.0.6-py3-none-any.whl

    `recipe_searchers-0.0.6-py3-none-any.whl` 是一个Python库的压缩包,专为处理与食谱搜索相关的问题而设计。这个版本号`0.0.6`表明这是该库的第六次更新,`py3-none-any`表示它适用于Python 3版本,不依赖于特定的...

    Python库 | whtc.recipe.configmanager-1.1.2.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:whtc.recipe.configmanager-1.1.2.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    Python库 | recipe_scrapers-13.6.0-py3-none-any.whl

    Python库`recipe_scrapers-13.6.0-py3-none-any.whl`是一个专为Python开发者设计的工具,主要用于从网络上抓取食谱网站的数据。这个库可以帮助开发者方便地获取食谱的详细信息,如食材、步骤、烹饪时间等,从而构建...

    Python库 | gp.recipe.pip-0.5.3.tar.gz

    标题中的"Python库 | gp.recipe.pip-0.5.3.tar.gz"指的是一个特定版本的Python库,名为`gp.recipe.pip`,版本号为0.5.3,其源代码以tar.gz格式的压缩包形式提供。这种类型的文件在Python开发中常见,通常用于分发和...

    Python Web Scraping Cookbook: Over 90 proven recipes to get you scraping with Py

    Python Web Scraping Cookbook is a solution-focused book that will teach you techniques to develop high-performance scrapers and deal with crawlers, sitemaps, forms automation, Ajax-based sites, and ...

    recipe-scrapers, 用于抓取配方数据的python 包.zip

    recipe-scrapers, 用于抓取配方数据的python 包 配方刮削器 一个简单的网络擦洗工具,用于我在我的工程中使用的菜谱工具,这是一个。 不支持 python 2. pip install git git://github.com/hhursev/recipe-scraper

    Python库zc.recipe.testrunner-1.0.0b6-py2.4.egg

    `zc.recipe.testrunner` 是一个Python的测试运行器库,主要设计用于持续集成环境,它提供了灵活的方式来配置和运行Python的测试套件。这个库的名字来源于它的开发者组织 `zc`(Zope Community)以及它提供的功能,即...

Global site tag (gtag.js) - Google Analytics