Question

Write a function called, sameKeys, that takes in two dictionaries. The sameKeys function looks for keys that are found in bot

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

CODE

def sameKeys(diction1, diction2):

if diction1 is None or diction2 is None:

return None

diction3 = {}

for key in diction1:

if key in diction2:

lst = []

lst.append(diction1[key])

lst.append(diction2[key])

diction3[key] = lst

return diction3

dict1 = {1: 'a', 2: 'b', 3: 'c', 4: 5}

dict2 = {1: 333, 3: 'k', 4: ['o', 'p']}

print(sameKeys(dict1, dict2))

1 def sameKeys (dictionl, diction2): 2 if dictionl is None or diction2 is None: GCC 4.8.2] on Linux 1: Ca, 333], 3: Cc, k

Add a comment
Know the answer?
Add Answer to:
Write a function called, sameKeys, that takes in two dictionaries. The sameKeys function looks for keys...
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
  • Python 3 Define a function below, get_subset, which takes two arguments: a dictionary of strings (keys)...

    Python 3 Define a function below, get_subset, which takes two arguments: a dictionary of strings (keys) to integers (values) and a list of strings. All of the strings in the list are keys to the dictionary. Complete the function such that it returns the subset of the dictionary defined by the keys in the list of strings. For example, with the dictionary ("puffin": 5, "corgi": 2, "three": 3) and the list ("three", "corgi"), your function should return {"corgi": 2, "three"...

  • 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...

  • Dictionaries

    1)You are given a variable, wwII_battle_winners , that is associated with a dictionary that maps the names of World War II battles to the victors of WWII battles. Writesome code that associates a sorted list of the battle names that appear as keys in this dictionary with the variable battles .2)The inverse of a map is a new map where the values of the original map become the keys of the new map and the keys become the values. For...

  • Phython read_file (fp)  D1,D2,D3: a) This function read a file pointer and returns 3 dictionaries:...

    Phython read_file (fp)  D1,D2,D3: a) This function read a file pointer and returns 3 dictionaries: - Parameters: file pointer (fp) - Returns : 3 dictionaries of list of tuples - The function displays nothing b) You must use the csv.reader because some fields have commas in them. c) Each row of the file contains the name of a video game, the platform which it was released, the release year, the genre (i.e. shooter, puzzle, rpg, fighter, etc.), the publishing...

  • using python Write a function that takes a dictionary and a list of keys as 2...

    using python Write a function that takes a dictionary and a list of keys as 2 parameters. It removes the entries associated with the keys from the given dictionary Your function should not print or return anything. The given dictionary should be modified after the function is called Note: it means that you can't create another dictionary in your function. Since dictionaries are mutable, you can modify them directly def remove_keys (dict, key_list) "" "Remove the key, value pair from...

  • 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....

  • Python 3, nbgrader, pandas 0.23.4 Q2 Default Value Functions (1 point) a) Sort Keys Write a function called sort_keys, which will return a sorted version of the keys from an input dictionary Input(s...

    Python 3, nbgrader, pandas 0.23.4 Q2 Default Value Functions (1 point) a) Sort Keys Write a function called sort_keys, which will return a sorted version of the keys from an input dictionary Input(s): dictionary :dictionary reverse boolean, default: False Output(s): .sorted_keys: list Procedure(s) Get the keys from the input dictionary using the keys()method (this will return a list of keys) Use the sorted function to sort the list of keys. Pass in reverse to sorted to set whether to reverse...

  • Hi, I need help with Python Dictionaries please. Question: Write a function named "add_key_value" that takes...

    Hi, I need help with Python Dictionaries please. Question: Write a function named "add_key_value" that takes a key-value store as a parameter with strings as keys and integers as values. The function will add a key-value pair to the input store with a key of "slam" and a value of 39. There is no need to return any value. Thanks!

  • Make a function dict build(keys, values) which takes as argument two lists, one containing keys, one...

    Make a function dict build(keys, values) which takes as argument two lists, one containing keys, one values to be put into a dictionary (in order). If the lists are of the same length put them into a dictionary form, and return the dictionary from the function. Otherwise return the keyword None from the function. For example: Test print(di ct_build(['a', 'b' , 'c'], [1,2,3])={ 'a': 1, 'b': 2, 'c': 3 r example: Result ildCC'a', 'b', 'c'], [1,2,3])-= { 'a': 1, 'b':...

  • # 1111111111111111111111111111111111111111111111111 # draw_histogram() #-------------------------------------------------- #-------------------------------------------------- """ Define the draw_histogram() function which is passed a Python...

    # 1111111111111111111111111111111111111111111111111 # draw_histogram() #-------------------------------------------------- #-------------------------------------------------- """ 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...

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
ADVERTISEMENT