How to Count the number of distinct keys in a dictionary in django template

Solution for How to Count the number of distinct keys in a dictionary in django template
is Given Below:

The numbers are serial number and the dictionary belongs to that serial number is data. I want to count the length of dictionary belong to distinct serial number in django template.
The name of dictionary is redict.

{15: [<videoscomment: Reply...byNavneetKaur>, <videoscomment: Reply...byNavneetKaur>], 20: [<videoscomment: 2nd comment reply...byNavneetKaur>]}

I have tried the following methods

comments.sno is the number and below gets data belong to that number

redict|get_val:comments.sno

and i put count in the last to get the length of data.

redict|get_val:comments.sno.count

And remember we have to do that in django template.

1 If you are familiar with annotations :

querysetname = Model.objects.all().annotate(Count('The_Distinct_Field_REQD', 
                                         distinct=True))

Or creating a set of the queryset will give only distinct elements since Sets do not allow duplicate values,

queryset = already_created_queryset
distinct_count = set(queryset).count() //add this line alone

or

distinct_count = Model.objects.all(filter as per your condition).distinct('field1',...'n_fields').count() 

2 Pass the calculated distinct count through the context dictionary :

context = {
    'dist_count' : distinct_count
}

3 Use the dist_count in the template