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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:20:11+00:00 2026-05-22T14:20:11+00:00

Update: Hello again. My question is, how can I compare values of an dictionary

  • 0

Update:

Hello again. My question is, how can I compare values of an dictionary for equality. More Informationen about my Dictionary:

  • keys are session numbers
  • values of each key are nested lists -> f.e.

    [[1,0],[2,0],[3,1]]

  • the length of values for each key arent the same, so it could be that session number 1 have more values then session number 2

  • here an example dictionary:

order_session =
{1:[[100,0],[22,1],[23,2]],10:[100,0],[232,0],[10,2],[11,2]],22:[[5,2],[23,2],….],
… }

My Goal:

Step 1: to compare the values of session number 1 with the values of the whole other session numbers in the dictionary for equality

Step 2: take the next session number and compare the values with the other values of the other session numbers, and so on
– finally we have each session number value compared

Step 3: save the result into a list f.e.
output = [[100,0],[23,2], … ] or output = [(100,0),(23,2), … ]

  • if you can see a value-pair [100,0] of session 1 and 10 are the same. also the value-pair [23,2] of session 1 and 22 are the same.

Thanks for helping me out.

Update 2

Thank you for all your help and tips to change the nested list of lists into list of tuples, which are quite better to handle it.

I prefer Boaz Yaniv solution 😉
I also like the use of collections.Counter() … unlucky that I use 2.6.4 (Counter works at 2.7) maybe I change to 2.7 sometimes.

  • 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-22T14:20:11+00:00Added an answer on May 22, 2026 at 2:20 pm

    If your dictionary is long, you’d want to use sets, for better performance (looking up already-encountered values in lists is going to be quite slow):

    def get_repeated_values(sessions):
        known = set()
        already_repeated = set()
        for lst in sessions.itervalues():
            session_set = set(tuple(x) for x in lst)
            repeated = (known & session_set) - already_repeated
            already_repeated |= repeated
            known |= session_set
            for val in repeated:
                yield val
    
    sessions = {1:[[100,0],[22,1],[23,2]],10:[[100,0],[232,0],[10,2],[11,2]],22:[[5,2],[23,2]]}
    for x in get_repeated_values(sessions):
        print x
    

    I also suggest (again, for performance reasons) to nest tuples inside your lists instead of lists, if you’re not going to change them on-the-fly. The code I posted here will work either way, but it would be faster if the values are already tuples.

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

Sidebar

Related Questions

UPDATE The issue is solved, all the code you can see works. Hello! I
Hello I need to do something like this: UPDATE tbl SET pozn=CONCAT(pozn, '+attach_str+') WHERE
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
Update: giving a much more thorough example. The first two solutions offered were right
UPDATE - A comprehensive comparison, updated as of February 2015, can be found here:
I had a previous question can jquery ajax call external webservice? and some good
I know this sounds like a broad question but I can narrow it down
Hello again stackoverflow... Once again I have a troublesome problem. I have a page
Hello is possible to switch between DML commands/operations (Insert,Delete,Update) on Trigger Body?, I try
Hey, sorry to bother you again, but I can't get this to work and

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.