[Tutor] use of the newer dict types

Jim Mooney cybervigilante at gmail.com
Fri Jul 26 01:03:28 CEST 2013


Dave Angel <davea at davea.name>

> What's not clear to me is whether this dictionary view object is safe to use
> when the dictionary is changing.  The page referenced above seems to say
> both yes and no.

Ah, now that makes some sense - they literally change as the
dictionary does. That could be useful:

>>> kv = {'b': 'beta', 'c': 'cappa', 'a': 'kark', 'd': 'delta', 'e': 'epsilon'}
>>> kvkeys = kv.keys()
>>> kvkeys
dict_keys(['b', 'c', 'a', 'd', 'e'])
>>> del kv['b']
>>> kv
{'a': 'kark', 'c': 'cappa', 'd': 'delta', 'e': 'epsilon'}
>>> kvkeys
dict_keys(['c', 'a', 'd', 'e'])  # b is missing

Jim

"Now Operation 7 must either bring out a result equal to zero (if
n=1); or a result greater than zero, as in the present case; and the
engine follows the one or the other of the two courses just explained,
contingently on the one or the other result of Operation 7." --Ada
Lovelace, the first computer programmer, describes the very first
computable if-then. She was followed by Grace Hopper, the COBOL
genius. Men were slower to take up the profession of programming ;')


More information about the Tutor mailing list