Python: can I have a list with named indices?

前端 未结 8 1627
天涯浪人
天涯浪人 2020-12-10 10:06

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

$shows = Array(0 => Array(\'id\' => 1, \'name\' => \'Sesame Street\'), 
               


        
8条回答
  •  孤街浪徒
    2020-12-10 10:58

    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.

提交回复
热议问题