2001 Enchancement Wishlist
Gareth McCaughan
Gareth.McCaughan at pobox.com
Fri Dec 29 17:14:36 EST 2000
Raymond Hettinger wrote:
> 4. Allow dictionaries to respond to sequence operations as if .keys() were
> in the list object. Examples:
>
> knights = { 'lancalot':'good', 'gallahad':'brave', 'robin':'coward' }
> for name in knights:
> print name, knights[name]
> print knights.len()
> if 'arthur' in knights:
> print 'Not the King'
> print knights[0] # may be any one depending on the hash table order
> try:
> print knights[5]
> except IndexError:
> print 'Too few knights for the ladies in the castle'
> del knights['lancelot'] # regular mapping operations left unchanged.
Nope.
| >>> knights = {}
| >>> knights[0] = 'foo'
| >>> knights[0]
| 'foo'
| >>> knights[1] = 'bar'
| >>> knights.keys()
| [1, 0]
Uh-oh.
--
Gareth McCaughan Gareth.McCaughan at pobox.com
sig under construc
More information about the Python-list
mailing list