私はPythonのn00bであり、シェルとPHPスクリプトから得た知識をPythonに取り入れようとしています。私は実際に、(コードを理解しやすい形に保ちながら)内部の値を作成および操作する概念を理解しようとしています。
LISTSとMAPPINGS(dict())のPython実装を利用するのに問題があります。基本配列(Pythonリスト)内で連想配列(Pythonマッピング)を使用する必要があるスクリプトを書いています。リストでは、一般的なINTインデックスを使用できます。
ありがとう!
これが私が現在持っているものです:
''' Marrying old-school array concepts
[in Python verbiage] a list (arr1) of mappings (arr2)
[per my old-school training] a 2D array with
arr1 using an INT index
arr2 using an associative index
'''
arr1 = []
arr1[0] = dict([ ('ticker'," "),
('t_date'," "),
('t_open'," "),
('t_high'," "),
('t_low'," "),
('t_close'," "),
('t_volume'," ")
] )
arr1[1] = dict([ ('ticker'," "),
('t_date'," "),
('t_open'," "),
('t_high'," "),
('t_low'," "),
('t_close'," "),
('t_volume'," ")
] )
arr1[0]['t_volume'] = 11250000
arr1[1]['t_volume'] = 11260000
print "\nAssociative array inside of an INT indexed array:"
print arr1[0]['t_volume'], arr1[1]['t_volume']
PHPでは、次の例が機能しています。
'''
arr_desired[0] = array( 'ticker' => 'ibm'
't_date' => '1/1/2008'
't_open' => 123.20
't_high' => 123.20
't_low' => 123.20
't_close' => 123.20
't_volume' => 11250000
);
arr_desired[1] = array( 'ticker' => 'ibm'
't_date' => '1/2/2008'
't_open' => 124.20
't_high' => 124.20
't_low' => 124.20
't_close' => 124.20
't_volume' => 11260000
);
print arr_desired[0]['t_volume'],arr_desired[1]['t_volume'] # should print>>> 11250000 11260000
'''