what I'd like to do is something like:
sum([probabilities[ngram] for ngram in combination if probabilities.has_key(ngram)])
this part is just fine. What I'd like to do is make something which handles a 'base case', that is to say assumes a certain probability, say .0001,
if not probabilities.has_key(ngram):
sum([probabilities[ngram] for ngram in combination if probabilities.has_key(ngram) else 开发者_C百科.0001])
Where probabilities is a dict with ntuples as keys and floats as values, combination is a list of ntuples.
edit fixed some brackets
No.
sum(probabilities.get(ngram, 0.0001) for ngram in combination)
精彩评论