UnkwnTech UnkwnTech - 1 year ago 62
Python Question

Python: can I have a list with named indices?

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'));

Is this possible in Python?

Answer Source

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"},

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download