I am really new to python and I can’t find any information about this. I have an associative array item,
item['id'] = 0
item['title'] = 'python'
I want to validate the contents of item but I dont want to use the index name like 'title' but just have a for loop and iterate over all entries in item regardless of their meaning. Something like that
for a in range(0, len(item)):
print (item[a])
Any ideas or suggestions?
In Python, associative arrays are called dictionaries.
A good way to iterate through a dict is to use
.iteritems():If you only need the values, use
.itervalues():As you learn more about Python and dictionaries, take note of the difference between
.iteritems()/itervalues()(which returns an iterator) anditems()/values()(which returns a list (array)).In Python 3
.iteritems()/.itervalues()have been removed anditems()/values()/keys()return iterators on the corresponding sequences.