When doing practice problems, I often times need to build a dict with keys as elements from an array and values as frequencies in which they appear. I usually do something like:
charFreqs = {}
for c in myStr:
if c in charFreqs:
charFreqs[c] += 1
else:
charFreqs[c] = 1
This works fine, but I am wondering if there is a more concise method. It seems like a lot of code to accomplish a pretty simple and common task.