如何迭代Python中的哈希列表?

时间:2018-02-19 03:03:31

标签: python list loops hash

我想从A_TABLE获取数组SIZE的元素,就像它在下面的顶部显示的那样,但是有一个迭代器,因为我完全没有在底部做。 大约一个小时之前是Python的新手,我一直在寻找,但任何建议都值得赞赏。

SIZE   = ('too small', 'just right', 'too large')

A_TABLE = {}
A_TABLE['size'] = SIZE
print "size is " + A_TABLE['size'][0]
print "size is " + A_TABLE['size'][1]
print "size is " + A_TABLE['size'][2]

for x in A_TABLE['size'][x]:
    print "size is " + A_TABLE['size'][x]

1 个答案:

答案 0 :(得分:1)

你以错误的方式循环,这是你应该怎么做的:

SIZE = ('too small', 'just right', 'too large')

A_TABLE = {}
A_TABLE['size'] = SIZE

for x in A_TABLE['size']: # change here
    print "size is " + x  # and here