社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

初始化python Defaultdict

samuelbrody1249 • 5 年前 • 1577 次点击  

component_map = {}
component_map[component] = {'in': [], 'out': [], 'degree': 0}

例如,我可以创建 defaultdict 那会给我一个 []

from collections import defaultdict
component_map = defaultdict(list)
component_map['component']
# []

我如何初始化它以便调用 component_map['component'] 回报 {'in': [], 'out': [], 'degree': 0} ?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54340
 
1577 次点击  
文章 [ 1 ]  |  最新文章 5 年前
wjandrea peer
Reply   •   1 楼
wjandrea peer    5 年前

这样地:

component_map = defaultdict(lambda: {'in': [], 'out': [], 'degree': 0})