union max( [ ] [ ]collections counter ({' ' ' ' }the most important operations for set are add( ) remove( ) discard( ) in sas well as < (is subset of )and (elements in that are not in tthe basic operations on the three key-value collections are similar to those on set one difference is with iterators--iteration over key-value collection yields the keys to iterate over the key-value pairsiterate over items()to iterate over valuesuse values((the keys(method returns an iterator to the keys not every type is "hashable" can be added to set or used as key in dict in particularmutable containers are not hashable--this is to prevent client from modifying an object after adding it to the containersince the lookup will then fail to find it if the slot that the modified object hashes to is different note that the built-in hash(function can greatly simplify the implementation of hash function for user-defined classi implementing __hash(self)__ is an anonymous letter constructiblewrite program which takes text for an anonymous letter and text for magazine and determines if it is possible to write the anonymous letter using the magazine the anonymous letter can be written using the magazine if for each character in the anonymous letterthe number of times it appears in the anonymous letter is no more than the number of times it appears in the magazine hintcount the number of distinct characters appearing in the letter solutiona brute force approach is to count for each character in the character set the number of times it appears in the letter and in the magazine if any character occurs more often in the letter than the magazine we return falseotherwise we return true this approach is potentially slow because it iterates over all charactersincluding those that do not occur in the letter or magazine it also makes multiple passes over both the letter and the magazine--as many passes as there are characters in the character set better approach is to make single pass over the letterstoring the character counts for the letter in single hash table--keys are charactersand values are the number of times that character appears nextwe make pass over the magazine when processing character cif appears in the hash tablewe reduce its count by we remove it from the hash when its count goes to zero if the hash becomes emptywe return true if we reach the end of the letter and the hash is nonemptywe return false--each of the characters remaining in the hash occurs more times in the letter than the magazine def is_letter_constructible_from_magazine letter_text magazine_text )compute the frequencies for all chars in letter_text char_frequency_for_letter collections counter letter_text checks if characters in magazine_text can cover characters in char_frequency_for_letter for in magazine_text if in char_frequency_for_letter