Next consider the invert_dict function from Section 11.5 of your textbook.
# From Section 11.5 of:
# Downey, A. (2015). Think Python: How to think like a computer scientist. Needham, Massachusetts: Green Tree Press.
def invert_dict(d):
inverse = dict()
for key in d:
val = d[key]
if val not in inverse:
inverse[val] = [key]
else:
inverse[val].append(key)
return inverse
Modify this function so that it can invert your dictionary. In particular, the function will need to turn each of the list items into separate keys in the inverted dictionary.
Run your modified invert_dict function on your dictionary. Print the original dictionary and the inverted one.
Include your Python program and the output in your Learning Journal submission.
Describe what is useful about your dictionary. Then describe whether the inverted dictionary is useful or meaningful, and why.
Create a Python dictionary that returns a list of values for each key. The key can be whatever type you want.
Design the dictionary so that it could be useful for something meaningful to you. Create at least three different items in it.
. Create a List / generic collection of 5 capital city names in Africa.
Display all the capital cities.
Insert Ghana capital city to element 3.
. Create a generic collection that stores even numbers from 2 to 20.
Display only the first element of the List.
.Create a delegates that accepts a number from user and displays whether the number is even or odd.
1. Create a delegate that displays a message (" you are underage" ) if the user's age is less than 18 and (you qualify to be an adult") if the age is greater than 18.
Python Program
Write a program to print the following, Given a word W and pattern P, you need to check whether the pattern matches the given word.The word will only contain letters(can be Uppercase and Lowercase). The pattern can contain letters, ? and *.
? : Can be matched with any single letter.
* : Can be matched with any sequence of letters (including an empty sequence).
If the pattern matches with the given word, print True else False.
Sample Input1
3
Hello *l?
Hell He?ll
Hell ?*
Sample Output1
True
False
True
Sample Input1
3
Hello Hell*
Hell He*ll
Hell hell*
Sample Output1
True
True
False
Write a program to print the following output.
Input
The first line contains a string.
The second line contains some space-separated strings.
Output
The output should be a single integer.
Explanation
scramble word = "tacren"
guessed words = ["trance", "recant"]
Since "trance" and "recant" both have length 6 then you score 54 pts each.
So the output is 108.
Sample Input1
rceast
cat create sat
Sample Output1
2
Sample Input2
tacren
trance recant
Sample Output2
108
Instructions:
Sample Results:
Input
Multiple lines containing an integer.
2
6
Output
Multiple lines containing an integer.
4
36
Create a structure called fraction. It has two members, both type int, called numerator and
denominator. Write a program that input values in two variables of type fraction. Add both
fractions and print the result in fraction format.