Home › Interview Questions › Given the string `text = "python is easy and pytho…

Given the string `text = "python is easy and python is powerful"`, count the words and store the counts in a dictionary using Python.

🟢 Easy Coding Fresher level
1Times asked
Jun 2026Last seen
Jun 2026First seen

💡 Model Answer

Split the string on whitespace to get a list of words, then iterate and count each word using a dictionary. Complexity is O(n) where n is the number of words. Example:

python
text = "python is easy and python is powerful"
words = text.split()
counts = {}
for w in words:
    counts[w] = counts.get(w, 0) + 1
print(counts)

Output: {'python': 2, 'is': 2, 'easy': 1, 'and': 1, 'powerful': 1}.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.

Get Assisting AI — Starts at ₹500