标签:style blog http os 2014 for
Suppose you are given a string and you want to count how many times each letters appears. There are several ways you do it:
Each of these options performs the same computation, but each of them implements that computation in a different way. An implementation is a way of performing a computation; some implementations are better than others. For example, an advantage of the dictionary implementation is that we don’t have to know ahead of time which letters appear in the string and we only have to make room for the letters that do appear. Here we can use the word list in word study.
Dictionaries have a method called get that takes a key and a default value. If the key appears in the dictionary, get returns the corresponding value; otherwise it returns the default value.
from Thinking in Python
Dictionary as a set of counters,布布扣,bubuko.com
Dictionary as a set of counters
标签:style blog http os 2014 for
原文地址:http://www.cnblogs.com/ryansunyu/p/3842514.html