- Learn Programming in Python with Cody Jackson
- Cody Jackson
- 294字
- 2021-06-10 19:06:10
Dictionaries
Next to lists, dictionaries are one of the most useful data types in Python. Python lists, as previously shown, are ordered collections that use a numerical offset. To select an item in a list, you need to know its position within the list. Python dictionaries are unordered collections of objects, matched to a key name; in other words, you can reference an item simply by knowing its associated key.
Because of their construction, dictionaries can replace many typical search algorithms and data structures found in C and related languages. For those coming from other languages, Python dictionaries are just like a hash table or associative array, where an object is mapped to a key name.
Dictionaries include the following properties:
- They are accessed by a key, not an offset. Each item in the dictionary has a corresponding key; the key is used to call the item.
- Stored objects are in a random order to provide faster lookup. When created, a dictionary stores items in a particular order that makes sense to Python, but may not make sense to the developer.
- To get a value, simply supply the key. If you need to order the items within a dictionary, there is a container called OrderedDict that was added in Python 2.7, but it has to be imported from the collections library.
- Dictionaries are variable-length, can hold objects of any type (including other dictionaries), and support deep nesting (multiple levels of items can be in a dictionary, such as a list within a dictionary within another dictionary).
- They are mutable but can't be modified like lists or strings. They are the only data type that supports mapping; that is, a key is linked to a value.
Internally, a dictionary is implemented as a hash table.
- Java Web開發學習手冊
- INSTANT FreeMarker Starter
- 深入淺出Spring Boot 2.x
- Three.js開發指南:基于WebGL和HTML5在網頁上渲染3D圖形和動畫(原書第3版)
- 數據結構(Python語言描述)(第2版)
- ASP.NET 3.5程序設計與項目實踐
- 領域驅動設計:軟件核心復雜性應對之道(修訂版)
- 深度實踐KVM:核心技術、管理運維、性能優化與項目實施
- 30天學通C#項目案例開發
- Visual Basic 程序設計實踐教程
- Deep Learning for Natural Language Processing
- Python無監督學習
- 軟硬件綜合系統軟件需求建模及可靠性綜合試驗、分析、評價技術
- Clojure Data Structures and Algorithms Cookbook
- Android熱門應用開發詳解