user
Generate the Python code to count the frequency of each character in a string.

String: "Hello world!"


assistant
char_freq = {}

for char in 'Hello world!':
  if char in char_freq:
    char_freq[char] += 1
  else:
    char_freq[char] = 1

print(char_freq)