---
title: "【Python 2.7/3.1 新特性】字典推导式（Dictionary comprehensions）"
author: "Suninny"
date: "2010-09-15T10:17:43Z"
tags: []
categories: ["编程语言"]
slug: "python-2-7-3-1-dictionary-comprehensions"
draft: false
lastmod: "2010-09-15T10:21:32Z"
id: 763585
url: "https://suninny.iteye.com/blog/763585"
---

L = \[1,2,3,4,5,6,7,8,9]

 

要生成下面这样的字典：

{1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60, 7: 70, 8: 80, 9: 90}

 

以前需要这样：

dict(\[(v, v\*10) for v in L])

 

现在可以直接这样：

{v: v\*10 for v in L}