2. keys() and values() -- Arrays vs Lists



The instructions say that "Whereas items() returns an array of tuples with each tuple consisting of a key/value pair from the dictionary"

Does the instructions mean list here? Because while I get what they mean by "an array of tuples," I don't think we've learned about arrays in Python yet--so far we've only covered lists and dictionaries. Aren't arrays some kind of module or something?

In other words, is this a typo by referring to "array of tuples" or am I missing something here?



Array and list are interchangeable terms.

[(key, value), (key, value), (key, value)]

>>> item_dict = {'a':1, 'b':2, 'c':3, 'd':4}
>>> item_dict.items()
dict_items([('a', 1), ('c', 3), ('d', 4), ('b', 2)])

The above is an array of tuples. We could have said it is a list of tuples, which means the exact same thing.


I agree that it is confusing....
but if you get in contact with several Programming languages
each of those Programming Language has its own =naming= of its structures.

a python-list is an Array...
Please read

google search
python list vs tuple vs array site:stackoverflow.com
ruby vs javascript vs python datatype site:stackoverflow.com


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.