In PHP I can name my array indices so that I may have something like:
$shows = Array(0 => Array(\'id\' => 1, \'name\' => \'Sesame Street\'),
PHP arrays are actually maps, which is equivalent to dicts in Python.
Thus, this is the Python equivalent:
showlist = [{'id':1, 'name':'Sesaeme Street'}, {'id':2, 'name':'Dora the Explorer'}]
Sorting example:
from operator import attrgetter
showlist.sort(key=attrgetter('id'))
BUT! With the example you provided, a simpler datastructure would be better:
shows = {1: 'Sesaeme Street', 2:'Dora the Explorer'}
The pandas
library has a really neat solution: Series
.
book = pandas.Series( ['Introduction to python', 'Someone', 359, 10],
index=['Title', 'Author', 'Number of pages', 'Price'])
print book['Author']
For more information check it's documentation: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.html.