Comparison of programming languages (associative array): Difference between revisions

Content deleted Content added
m C#: clarify
Python: +Py3k dict comprehension
Line 845:
</source>
 
Dictionary keys can be individually deleted using the del statement. The corresponding value can be returned before the key-value pair are deleted using the pop method of dict types;:
 
<source lang="python">
Line 851:
val = phonebook.pop('Sally Smart')
assert phonebook.keys() == ['J. Random Hacker'] # Only one key left
</source>
 
Python 3.0 also supports dictionary comprehensions, a compact syntax for generating a dictionary from any iterator:
<source lang="python">
square_dict={i:i*i for i in range(5)}
assert square_dict == {0: 0, 1: 1, 2: 4, 3: 9, 4: 16}
</source>