我很羡慕 9 11 12 楼的
我是新手.花了一会时间才看明白.
用的不是很明白....
我刚看完 入门书
我觉得 我写的这个部是 代码最少的.只是是最容易理解的..
python 很有意思..可惜大学毕业了才知道有这么好的语言.
s='here is a sample of english text'
d={}
for l in set(s):
d[l]=s.count(l)
print (d)
import collections
print (dict(collections.Counter('here is a sample of english text')))
>>>{'a': 2, ' ': 6, 'e': 5, 'g': 1, 'f': 1, 'i': 2, 'h': 2, 'm': 1, 'l': 2, 'o': 1, 'n': 1, 'p': 1, 's': 3, 'r': 1, 't': 2, 'x': 1}
我是新手.花了一会时间才看明白.
用的不是很明白....
我刚看完 入门书
我觉得 我写的这个部是 代码最少的.只是是最容易理解的..
python 很有意思..可惜大学毕业了才知道有这么好的语言.
s='here is a sample of english text'
d={}
for l in set(s):
d[l]=s.count(l)
print (d)
import collections
print (dict(collections.Counter('here is a sample of english text')))
>>>{'a': 2, ' ': 6, 'e': 5, 'g': 1, 'f': 1, 'i': 2, 'h': 2, 'm': 1, 'l': 2, 'o': 1, 'n': 1, 'p': 1, 's': 3, 'r': 1, 't': 2, 'x': 1}