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


#1



https://www.codecademy.com/courses/python-beginner-en-KAgt5/0/2?curriculum_id=4f89dab3d788890003000096

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?

Thanks.



#2

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.


#3

@samuelcavalier,
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
http://stackoverflow.com/questions/626759/whats-the-difference-between-list-and-tuples

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


#4

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