w3resource

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:

Flowchart: Count the number of students of individual class

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.



Follow us on Facebook and Twitter for latest update.