我是Python的一个n00b,我正试图将我所掌握的一点知识从shell和PHP脚本应用到Python中。我真的在努力掌握在其中创建和操作值的概念(同时保持代码的可理解形式)。在
我在使用列表和映射(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中,我有以下示例:
^{pr2}$
博主是一名Python新手,尝试将之前在shell和PHP中的知识应用到Python中,尤其是理解如何在Python中创建和操作值。问题在于如何在列表中使用映射,即在Python中创建一个2D数组,其中第一维用INT索引,第二维用关联数组(映射)索引。示例展示了如何在Python列表中定义和操作字典,包括如何通过键来访问和修改字典值。
190

被折叠的 条评论
为什么被折叠?



