I've always used dictionaries. I write in Python.
|
21
5
| |
|
add a comment
|
|
80
|
A dictionary is a general concept that maps keys to values. There are many ways to implement such a mapping. A hashtable is a specific way to implement a dictionary. Besides hashtables, another common way to implement dictionaries is red-black trees. Each method has it's own pros and cons. A red-black tree can always perform a lookup in O(log N). A hashtable can perform a lookup in O(1) time although that can degrade to O(N) depending on the input. | ||||||||
|
|
19
|
A dictionary is a data structure that maps keys to values. A hash table is a data structure that maps keys to values by taking the hash value of the key (by applying some hash function to it) and mapping that to a bucket where one or more values is stored. IMO this is analogous to asking the difference between a list and a linked list. For clarity it may be important to note that it MAY be the case that Python currently implements their dictionaries using hash tables, and it MAY be the case in the future that Python changes that fact without causing their dictionaries to stop being dictionaries. | ||||||||||||||||||||
|
|
12
|
"A dictionary" has a few different meanings in programming, as wikipedia will tell you -- "associative array", the sense in which Python uses the term (also known as "a mapping"), is one of those meanings (but "data dictionary", and "dictionary attacks" in password guess attempts, are also important). Hash tables are important data structures; Python uses them to implement two important built-in data types, So, even in Python, you can't consider "hash table" to be a synonym for "dictionary"... since a similar data structure is also used to implement "sets"!-) | ||
|
5
|
A Python dictionary is internally implemented with a hashtable. | ||||
|

本文探讨了字典和哈希表之间的区别,解释了字典作为一种将键映射到值的概念,可以通过多种方式实现,而哈希表是实现字典的一种具体方法。文章还讨论了不同实现方式的优缺点。
2177






