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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:58:35+00:00 2026-06-15T04:58:35+00:00

I need help on how to remove duplicate items in a tuple of a

  • 0

I need help on how to remove duplicate items in a tuple of a dictionary.

dict of {tuple of (str, str, str, str): int}) -> tuple of (str, None)

Here is the dictionary:

   {('ALPHA', 'BETA', 'GAMMA', 'DELTA'): 5
    ('BETA', 'GAMMA', 'ALPHA', 'DELTA'): 3
    ('DELTA', 'BETA', 'GAMMA', 'ALPHA'): 1
    ('GAMMA', 'DELTA', 'ALPHA', 'BETA'): 3
    ('BETA', 'ALPHA', 'DELTA', 'GAMMA'): 4}

and the integer is the value of the first index of the tuple such that I got to group them by:

def rad_type(particle):

   my_dict = {}

   for (k, v) in particle.items():
        if (k[0] in my_dict):
            my_dict[k[0]] += v
        else:
            my_dict[k[0]] = v

   return my_dict

This returns:

{'ALPHA': 5, 'BETA': 7, 'GAMMA': 3, 'DELTA': 1}

Since 'DELTA' has the least value which in this case is 1, but I want to remove the element like this:

   {('ALPHA', 'BETA', 'GAMMA'): 5
    ('BETA', 'GAMMA', 'ALPHA'): 7
    ('BETA', 'GAMMA', 'ALPHA'): 1
    ('GAMMA', 'ALPHA', 'BETA'): 3}

This gives ALPHA = 5, BETA = 8, GAMMA = 3; this is what I really need in terms of a dictionary.

I tried to remove the least element and it’s not working?

for (p, v) in my_dict.items():
        if (max(my_dict.values()) / sum(my_dict.values()):
            if (v == min(my_dict.values())):
                del my_dict[p]
        return my_dict

But this gives ALPHA = 5, BETA = 7, GAMMA = 3

Since this return a dictionary, how do I remove the duplicates with a tuple and return it back as a dictionary without importing anything?

The problem is similar to this.

  • 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-15T04:58:36+00:00Added an answer on June 15, 2026 at 4:58 am

    here is a suggestion ..
    if we use your function:

    def rad_type(particle):
    
       my_dict = {}
    
       for (k, v) in particle.items():
            if (k[0] in my_dict):
                my_dict[k[0]] += v
            else:
                my_dict[k[0]] = v
    
       return my_dict  
    

    and if we define another function that uses your function :

    def filter(dict):
            filter1 = rad_type(dict)
            i = 0
            for k ,val in dict.items():
                  dict[k] = filter1[k[0]]
                  i +=1
            mini_key = [k for k , val in filter1.items() if val == min([value for key ,  value in filter1.items()])][0] 
            filter2 = {tuple(y for y in key if y != mini_key):value for key, value in dict.items()}
            filter3 = rad_type(filter2)
            return filter3  
    

    if we apply this function on the dictionary particle :

    result = filter(particle)  
    

    the output is :

    {'ALPHA': 5, 'BETA': 8, 'GAMMA': 3}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am asking for your help with sed. I need to remove duplicate underscores
I need help to find the correct command, on android, to remove the blue
Who can help me with regular expression? I need to remove a part of
need help to create regular expression matching string www.*.abc.*/somestring Here * is wild card
Python: How to remove all duplicate items from a list Hey guys I have
I need to remove semi duplicate records from the following table ID PID SCORE
I'm new here and need help (first of all sorry for my english). I've
I need help to figure how can i remove duplicates chars from a string.
I need help to build a regex that can remove EVEN lines in a
I need some help in understanding when and why to use Remote Service instead

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.