Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
from collections import Counter, defaultdict sentence = "to be or not to be that is the question" wc = Counter(sentence.split()) print("Top 3 words:", wc.most_common(3)) print("Count of 'to':", wc["to"]) by_len = defaultdict(list) for w in sentence.split(): by_len[len(w)].append(w) print(dict(by_len))
Result
Open