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 8494625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:21:06+00:00 2026-06-10T23:21:06+00:00

EDIT: as @BrenBarn pointed out, the original didn’t make sense. Given a list of

  • 0

EDIT: as @BrenBarn pointed out, the original didn’t make sense.

Given a list of dicts (courtesy of csv.DictReader–they all have str keys and values) it’d be nice to remove duplicates by stuffing them all in a set, but this can’t be done directly since dict isn’t hashable. Some existing questions touch on how to fake __hash__() for sets/dicts but don’t address which way should be preferred.

# i. concise but ugly round trip
filtered = [eval(x) for x in {repr(d) for d in pile_o_dicts}]

# ii. wordy but avoids round trip
filtered = []
keys = set()
for d in pile_o_dicts:
    key = str(d)
    if key not in keys:
        keys.add(key)
        filtered.append(d)

# iii. introducing another class for this seems Java-like?
filtered = {hashable_dict(x) for x in pile_o_dicts}

# iv. something else entirely

In the spirit of the Zen of Python what’s the “obvious way to do it”?

  • 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-06-10T23:21:08+00:00Added an answer on June 10, 2026 at 11:21 pm

    The artfully named pile_o_dicts can be converted to a canonical form by sorting their items lists:

     groups = {}
     for d in pile_o_dicts:
         k = tuple(sorted(d.items()))
         groups.setdefault(k, []).append(d)
    

    This will group identical dictionaries together.

    FWIW, the technique of using sorted(d.items()) is currently used in the standard library for functools.lru_cache() in order to recognize function calls that have the same keyword arguments. IOW, this technique is tried and true 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT : It turned out that this can only be done through an external
Edit ok, great feedback here, got me pointed in the right direction. Use case
EDIT : Ok, I found out why. My getX and getY were overriding the
Edit: I think I figured out the solution, but I'm still interested to know
EDIT: I think I've worked something out. - This character - ’ - seems
EDIT: I'll try and make it clearer sorry for the confusion. I have two
Edit 1 begins The behaviour of the original post applies only to Windows XP
EDIT FOR CLARITY: I know what the 'head of empty list' error is and
EDIT: Learned that Webmethods actually uses NLST, not LIST, if that matters Our business
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code

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.