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

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

问题描述

在PHP我可以说出我的数组indicies,这样我可能碰到这样的:

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

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

在Python这可能吗?

Is this possible in Python?

推荐答案

这听起来像使用名为指数的PHP数组是非常相似的Python字典:

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更多关于这一点。

See http://docs.python.org/tutorial/datastructures.html#dictionaries for more on this.

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

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