menu COMPSCI 2120/9642/DIGIHUM 2220 1.0 documentation

Activity 3

_images/keysvals.png

This is Optional

This activity is optional. If you do not submit it it will not count towards your activity mark (and your mark will be out of the average between activities 1 and 2). If you do submit it it will count as 1 of 3 activities in your final activity mark.

What you need to do

  1. Write a function which takes 2 lists and puts them into a dictionary as keys and values, respectively. So, for example, if list1 is [0,3,5,6] then these would be the keys for your dictionary, and if list2 is [“a”, “b”, “c”, “d”] then these would be the values for your dictionary.

  2. If list1 has any duplicates, you must put the values corresponding to duplicate keys (i.e. those from list 2) into a tuple. See the code below for reference (note that 0 is a duplicate key, so both “Sara” and “David need to go into a tuple”)

>>> list1 = [0, 0, 5, 3, 2]
>>> list2 = ["Sara", "David", "Surya", "Kevin", "Vrund"]
>>> new_dict = make_dict(list1, list2)
>>> print(new_dict)
    {0: ("Sara", "David"), 5: "Surya", 3: "Kevin", 2: "Vrund"}

Call your function with the following test values for list1 and list2:

>>> list1 = [0,6,1,3,2,0,6,4,5,7,0,5]
>>> list2 = ["black cat", "fighting fish", "dog", "turtle", "horse", "tabby cat", "cichlid fish", "snail", "budgie", "lizard", "savannah cat", "parrot"]

What to submit (in zipped folder)

  1. Your python file (activity3.py) with all of your code.

  2. A text file with your output (output.txt). In your output you only need to print the dictionary resulting from your function call.