Python:我可以有一个带有命名索引的列表吗? [英] Python: can I have a list with named indices?

查看:22
本文介绍了Python:我可以有一个带有命名索引的列表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 PHP 中,我可以命名我的数组索引,以便我可以有类似的东西:

In PHP I can name my array indices so that I may have something like:

$shows = Array(0 => Array('id' => 1, 'name' => 'Sesame Street'), 
               1 => Array('id' => 2, 'name' => 'Dora The Explorer'));

这在 Python 中可行吗?

Is this possible in Python?

推荐答案

这听起来像使用命名索引的 PHP 数组与 Python dict 非常相似:

This sounds like the PHP array using named indices is very similar to a python dict:

shows = [
  {"id": 1, "name": "Sesaeme Street"},
  {"id": 2, "name": "Dora The Explorer"},
]

参见 http://docs.python.org/tutorial/datastructures.html#dictionaries 了解更多.

这篇关于Python:我可以有一个带有命名索引的列表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆