Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

Is this possible in Python?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
799 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...