The
len function also works for dictionaries but in this case it returns the number
of key-value pairs.
>>>print len(translator)
10
The in operator works on dictionaries and it tells you
whether something appears as a key in the dictionary.
>>>'five' in
translator
True
>>>'nine' in
translator
True
>>> 'ten' in
translator
True
>>> 'eleven' in
translator
False
So far we’ve been working with keys, but if we want to
work with values that is also possible. In order to see if the value appears in
>>>vals = translator.values()
>>>print 'cinque' in vals
True
No comments:
Post a Comment