Python Data Structure: Count the number of students of individual class
Python Data Structure: Exercise-7 with Solution
Write a Python program to count the number of students in an individual class.
Sample Solution:
Python Code:
from collections import Counter
classes = (
('V', 1),
('VI', 1),
('V', 2),
('VI', 2),
('VI', 3),
('VII', 1),
)
students = Counter(class_name for class_name, no_students in classes)
print(students)
Sample Output:
Counter({'VI': 3, 'V': 2, 'VII': 1})
Flowchart:
Python Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Python program to find the class wise roll number from a tuple-of-tuples.
Next: Write a Python program to get the unique enumeration values.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/python-exercises/data-structures-and-algorithms/python-data-structure-exercise-7.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics