Content deleted Content added
→Prolog: copy editing |
→Python: copy editing, linking, etc. |
||
Line 1,493:
Some versions of [[Prolog]] include dictionary ("dict") utilities.<ref>[http://www.swi-prolog.org/pldoc/man?section=dicts "Dicts: structures with named arguments"]</ref>
===
In [[Python]], associative arrays are called
<syntaxhighlight lang=Python>
Line 1,504:
</syntaxhighlight>
To access an entry in Python simply use the array indexing operator
<syntaxhighlight lang=Pycon>
>>> phonebook['Sally Smart']
'555-9999'
</syntaxhighlight>
<syntaxhighlight lang=Pycon>
Line 1,529 ⟶ 1,530:
</syntaxhighlight>
Dictionary keys can be individually deleted using the <code>del</code> statement. The corresponding value can be returned before the key-value pair
<syntaxhighlight lang=Pycon>
Line 1,538 ⟶ 1,539:
</syntaxhighlight>
Python 2.7 and 3.x also
<syntaxhighlight lang=Pycon>
>>> square_dict = {i: i*i for i in range(5)}
Line 1,547 ⟶ 1,549:
</syntaxhighlight>
Strictly speaking, a dictionary is a super-set of an associative array, since neither the keys or values are limited to a single datatype. One could think of a dictionary as an
<syntaxhighlight lang=Python>
|