您下面的代碼:
>>> from collections import defaultdict
>>> dict = defaultdict(int)
>>> for word in test.split():
... dict[word] += 1
...
>>> print dict #defaultdict(<type 'int'>, {'and': 2, 'already': 1, 'help': 1, 'just': 1, 'when': 1, 'is': 2, 'some': 1, 'back': 1, "they've": 1, 'really': 1, 'say': 1, 'customer': 1, 'have': 1, 'impossible': 1, 'trust': 1, '(which': 1, 'quite': 1, 'out': 1, 'even': 1, 'information': 1, 'confirmed': 1, 'court': 1, 'takes': 1, 'for': 1, 'also': 1, 'with': 2, '-': 1, 'been': 1, 'any': 2, 'to': 4, 'take': 1, 'They': 1, 'which': 1, 'taken': 1, 'you': 4, 'has': 1, 'cases.': 1, 'Nor': 1, 'gives': 1, 'do': 1, 'good': 1, 'week),': 1, 'that': 1, 'company': 1, 'after': 1, 'paid': 1, 'it': 1, 'abroad.': 1, 'but': 1, 'they': 2, 'not': 1, 'such': 1, 'bit': 1, 'chargebacks': 1, 'come': 1, 'payment': 1, 'a': 3, 'refuse': 1, "wasn't.": 1, 'of': 1, 'It': 1, 'responsibility': 1, 'can': 1, 'suggestion': 1, 'small': 1, 'claims': 1, 'the': 3, 'refer': 1})
我希望這將有助於.. :)
謝謝Nimi工作:)! –