the addition of a new key-value pair causes the size of the dictionary to
grow beyond its original size, it shall result in an error. True or False?
Justify?
Answers
Answer:
Learn to Program Using Python: Getting Started with Dictionaries
by Richard G. Baldwin
Learn about the characteristics of the Python dictionary, and how to use those basic characteristics of a dictionary.
Preface
Introduction
What Is a Dictionary?
Summary of Dictionary Characteristics
Sample Program
Summary
What's Next?
Review
Listing of Sample Program
Preface
This document is part of a series of online tutorial lessons designed to teach you how to program using the Python scripting language. After we cover regular Python, the lessons will cover JPython. This will form a link between Python and Java.
Viewing tip
Advertisement
You may find it useful to open another copy of this lesson in a separate browser window. That will make it easier for you to scroll back and forth among the different listings while you are reading about them.
Something for everyone
Beginners start at the beginning, and experienced programmers jump in further along. Learn to Program using Python: Lesson 1, Getting Started provides an overall description of this online programming course. (You will find a consolidated index to all of my Python, Java, and XML tutorials, including Lesson 1 mentioned above, on my website.)
Introduction
This is the beginning of a miniseries of lessons designed to teach you about dictionaries.
Containers or collections
In previous lessons, you learned about strings, lists, and tuples. Dictionaries fall in the same general family as these three types of objects (containers or collections), but with significant differences.
Preview
This lesson will introduce you to the characteristics of the Python dictionary, and will show you how to use the basic characteristics. Subsequent lessons will show you how to use the characteristics of dictionaries beyond the basics.
What Is a Dictionary?
Mutable unordered set...
A dictionary is a mutable unordered set of key:value pairs. Its values can contain references to any type of object.
In other languages, similar data structures are often called associative arrays or hash tables.
Not a sequence
Unlike the string, list, and tuple, a dictionary is not a sequence. The sequences are indexed by a range of ordinal numbers. Hence, they are ordered.
Indexed by keys, not numbers
Dictionaries are indexed by keys. According to the Python Tutorial, a key can be "any non-mutable type." Since strings and numbers are not mutable, you can always use a string or a number as a key in a dictionary.
What about a tuple as a key?
You can use a tuple as a key if all of the items contained in the tuple are immutable. Hence a tuple to be used as a key can contain strings, numbers, and other tuples containing references to immutable objects.
Explanation: