Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6840865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:53:47+00:00 2026-05-26T23:53:47+00:00

How can i find the count of duplicates in this list. >>> result =

  • 0

How can i find the count of duplicates in this list.

>>> result = SiteTags.objects.values('content_type','object_id')
>>> result
[{'object_id': 1, 'content_type': 46}, {'object_id': 1, 'content_type': 46}, {'object_id': 2, 'content_type': 42}]

Is there anyway to find in query? or through an other way?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:53:47+00:00Added an answer on May 26, 2026 at 11:53 pm
    set(tuple(sorted(r.iteritems())) for r in result)
    

    gives you a set of unique elements in this list. Take its length and compare it to len(result).

    To get each element and its count within the result:

    counter = {}
    for r in result:
        tup = tuple(sorted(r.iteritems()))
        counter[tup] = counter.get(tup, 0) + 1
    for tup, cnt in counter.iteritems():
        print dict(tup), cnt
    

    prints:

    {'object_id': 2, 'content_type': 42} 1
    {'object_id': 1, 'content_type': 46} 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this to find all duplicates in my db: SELECT phone, count(*) AS
I used the following query to find duplicates: SELECT userID, COUNT(userID) AS NumOccurrences FROM
This is bound to be a duplicate question but I can't find any others.
I think this isn't supposed to happen, but I can't find why this isn't
I have this query: SELECT COUNT(*) as clicks, DATE_FORMAT(FROM_UNIXTIME(click_date), '%w %M %Y') as point
This is a follow-up to this previous question: Complicated COUNT query in MySQL .
I have read almost every post I can find on this site. I have
I have a query as below to find duplicates in my table which contains
I'm sure this problem has been addressed before but I can't find a 'duplicate'.
I can find the JS and HTML code in response by alert() . But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.