The following procedural code snippet computes the character frequency of a text string and writes inside a dictionary. The dictionary has the characters as keys and the frequency as values.
text = "asampletextstring"
char_count = {}
for char in text:
if char_count.get(char):
char_count[char] += 1
else:
char_count[char] = 1
My question is, is it possible to rewrite the above snippet as a comprehension
?