Question

how to check if there are keys with the same values in a dictionary. python 3.0...

how to check if there are keys with the same values in a dictionary. python 3.0

for example:

what if there is a list within the values?

because when I try to make it a set, it comes up with an error: unhashable item 'list' .

eg. data = {'size': 4, 'entrance':(0, 0), 'exit':(0,1), 'treasure': [(0, 0)]}

I would like it to return None when there are keys with the same value, but not sure how to check it when some of them are in a list.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

# using in operator to

# get key and value

print ("Dict key-value are : ")

for i in test_dict :

    print(i, test_dict[i])

Add a comment
Know the answer?
Add Answer to:
how to check if there are keys with the same values in a dictionary. python 3.0...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Storing data and adding to data in a dictionary: Experiment with Python dictionaries and their keys()...

    Storing data and adding to data in a dictionary: Experiment with Python dictionaries and their keys() member function that returns a list of a dictionary's keys. You can check if a particular key is in a dictionary by using the in test with the keys list. For example, if our dictionary is MyDict = { 1: 'One', 2: 'Two', 3: 'Three' } Then ( 2 in MyDict.keys() ) evaluates to True, indicating that 2 is a valid key for MyDict....

  • I have a dictionary in which has strings for keys and integers for values. I need...

    I have a dictionary in which has strings for keys and integers for values. I need to count the length of each key and place it in one of three categories, small, medium or large. Those are defined by: small: length 0-4, inclusive. medium: length 5-7, inclusive. large: length 8+, inclusive. After they are they have been sorted into their appropriate category, the program needs to check which word of each small, medium, large category had the largest key. Sample...

  • Python 5. Write a function named grade_components that has one parameter, a dictionary. The keys for...

    Python 5. Write a function named grade_components that has one parameter, a dictionary. The keys for the dictionary are strings and the values are lists of numbers. The function should create a new dictionary where the keys are the same strings as the original dictionary and the values are tuples. The first entry in each tuple should be the weighted average of the non-negative values in the list (where the weight was the number in the 0 position of the...

  • In python, PART A: I am trying to get a dictionary with size(4, 5, 6) as...

    In python, PART A: I am trying to get a dictionary with size(4, 5, 6) as keys and an array for key containing a list of values (words from file of respective size) associated with those keys I am reading from a file of strings, where I am only interested with words of length 4, 5, and 6 to compute my program reading the text file line by line: At first, I have an empty dictionary then to that I...

  • PYTHON Define the remove_e_synonyms() function which is passed a dictionary as a parameter. The keys of...

    PYTHON Define the remove_e_synonyms() function which is passed a dictionary as a parameter. The keys of the parameter dictionary are words and the corresponding values are lists of synonyms (synonyms are words which have the same or nearly the same meaning). The function removes all the synonyms which contain the letter 'e' or 'E') from each corresponding list of synonyms. As well, the function sorts each corresponding list of synonyms. Note: the testing code makes use of the print_dict_in_key_order(a_dict) which...

  • 1. Define the draw_histogram() function which is passed a Python dictionary as a parameter. The keys...

    1. Define the draw_histogram() function which is passed a Python dictionary as a parameter. The keys of the dictionary are single letters and the corresponding values are integers, e.g., {'b': 5, 'a': 6, 'c': 3}. For each key:value pair in the dictionary the function prints the key, followed by ": ", followed by a series of stars. The number of stars printed is given by the value corresponding to the key. The keys are printed in alphabetical order. Note that...

  • Python Modify your program from Learning Journal Unit 7 to read dictionary items from a file...

    Python Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write the inverted dictionary to a file. You will need to decide on the following: How to format each dictionary item as a text string in the input file. How to covert each input string into a dictionary item. How to format each item of your inverted dictionary as a text string in the output file. Create an input file with your original...

  • Language: Python Topic: Dictionaries Function name: catch_flight Parameters: dictionary, tuple containing two strings Returns: dictionary Description:...

    Language: Python Topic: Dictionaries Function name: catch_flight Parameters: dictionary, tuple containing two strings Returns: dictionary Description: You’ve been stuck in NYC for around 8 months all by yourself because you haven’t been able to find a good time to fly home. You’re willing to go to any city but want to see how many flights to each location fit your budget. You’re given a dictionary that has city names (strings) as the keys and a list of prices (list) and...

  • I need to write a Python Program for the following question. Link for tallest mountains: https://en.wikipedia.org/wiki/List_of_mountains_by_elevation Use top 10 tallest mountains. Part One Wikipedia...

    I need to write a Python Program for the following question. Link for tallest mountains: https://en.wikipedia.org/wiki/List_of_mountains_by_elevation Use top 10 tallest mountains. Part One Wikipedia has a list of the tallest mountains in the world each mountain's elevation. Pick 10 mountains from this list. Create a dictionary with the mountain names as keys, and the elevations as values. Print out just the mountains' names, by looping through the keys of your dictionary. Print out just the mountains' elevations, by looping through...

  • This script will create a dictionary whose keys are all the directories listed in thePATH system...

    This script will create a dictionary whose keys are all the directories listed in thePATH system variable, and whose values are the number of files in each of these directories. The script will also print each directory entry sorted by directory name. The script will use the following five functions to get the required results get_environment_variable_value() get_dirs_from_path() get_file_count() get_file_count_for_dir_list() print_sorted_dictionary() get_environment_variable_value() The header for this function must be This function must accept a shell variable as its only parameter The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT