Junior — Middle
Could you name an example of your code that you are proud of and do not consider unsuccessful?
sobes.tech AI
Answer from AI
A Python code example I am proud of is the implementation of a function to count word frequency in text using standard libraries and generators:
from collections import Counter
def word_frequency(text):
words = (word.lower() for word in text.split())
return Counter(words)
# Example usage
text = "Hello world! Hello AI world."
freq = word_frequency(text)
print(freq) # Counter({'hello': 2, 'world!': 1, 'ai': 1, 'world.': 1})
This code is concise, efficient, and easily extendable, for example, to filter punctuation or stop words.