Question

For Python 3 MPLS please 1. Given a variable, unproved_conjectures, that is associated with a dictionary...

For Python 3 MPLS please

1. Given a variable, unproved_conjectures, that is associated with a dictionary that maps the common names of mathematical conjectures to the years when the conjectures were made, write a statement that deletes the entry for "Fermat's Last Theorem".

2. Given a dictionary d, create a new dictionary that reverses the keys and values of d. Thus, the keys of d become the values of the new dictionary and the values of d become the keys of the new dictionary. You may assume d contains no duplicate values (that is, no two keys map to the same values.) Associate the new dictionary with the variable inverse.

3. Given the dictionary, d, find the largest key in the dictionary and associate the corresponding value with the variable val_of_max. For example, given the dictionary {5:3, 4:1, 12:2}, 2 would be associated with val_of_max. Assume d is not empty.

4. Given the string line, create a set of all the vowels in line. Associate the set with the variable vowels.

5. Remove the smallest element from the set, s. If the set is empty, it remains empty.

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

1.

// Delete the entry for "Fermat's Last Theorem" from dictionary unproved_conjectures

keyToDelete = "Fermat's Last Theorem"

#checks if key Fermat's Last Theorem is present in unproved_conjectures

if keyToDelete in unproved_conjectures.keys():

               del unproved_conjectures[keyToDelete] # if present, delete it

2.

def reverse_dictionary(d):

inverse = {} # new dictionary

               d_keys = d.keys() # get the list of keys in d

               # loop to reverse the dictionary

               for key in d_keys:

inverse[d[key]] = key

               return inverse

3.

# function to return the value associated with the maximum key of dictionary

def maxKeyValue(d):

               d_keys = d.keys() # get the list of keys of dictionary, d

               # if dictionary is not empty

               if(len(d_keys) > 0):           

                              max = d_keys[0] # set the first key as max

                              # loop to find the maximum key

                              for i in range(1,len(d_keys)):

                                             if max < d_keys[i]:

                                                            max = d_keys[i]

                              return d[max] # return the value associated with maximum key

               else:

                              return None # no keys in dictionary

4.

# function that returns the set of all vowels in a string line                             

def vowels_set(str):

               vowels = set() # result set

               valid_vowels = 'aeiouAEIOU' # string of valid vowels

              

               # loop over each alphabet in the input string, str

               for alphabet in str:

                              if alphabet in valid_vowels: # if alphabet is vowel

                                             vowels.add(alphabet) # add to set

               return vowels                    #return the set

5.

# function to remove smallest element from input set, s   

def remove_smallest(s):

               if len(s) == 0: # if set s is empty then return

                              return

               minimum_item = min(s) # get the minimum element from set s

              

               s.discard(minimum_item) # remove the minimum element

Add a comment
Know the answer?
Add Answer to:
For Python 3 MPLS please 1. Given a variable, unproved_conjectures, that is associated with a dictionary...
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
  • Given a variable, unproved_conjectures, that is associated with a dictionary that maps the common names of...

    Given a variable, unproved_conjectures, that is associated with a dictionary that maps the common names of mathematical conjectures to the years when the conjectures were made, write a statement that deletes the entry for "Fermat's Last Theorem". In Python.

  • dictionary adding / removal

    Given a variable, unproved_conjectures, that is associated with a dictionary that maps the common names of mathematical conjectures to the years when the conjectures were made, write a statement that deletes the entry for "Fermat's Last Theorem".

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

  • PYTHON PROGRAM by using functions & dictionary or set. - must create a variable to hold...

    PYTHON PROGRAM by using functions & dictionary or set. - must create a variable to hold a dictionary or sets - must define a function that accepts dictionaries or sets as an argument A dictionary maps a set of objects (keys) to another set of objects (values). A Python dictionary is a mapping of unique keys to values. For e.g.: a dictionary defined as: released = { "iphone" : 2007, "iphone 3G": 2008, "iphone 3GS": 2009, "iphone 4" : 2010,...

  • 3 Dn Ent Write a python program to create a Dictionary named grade with the given...

    3 Dn Ent Write a python program to create a Dictionary named grade with the given items and do the below operations: i. 15 i. Create Dictionary with keys-{'Monday', 'Tuesday', 'Wednesday Thursday', 'Friday') ii. values-{1, 2, 3, 4, 5) ii. Now append another item with key-'Saturday') and value-(63 to the already created Dictionary and print it.

  • python 3 inheritance Define a class named bidict (bidirectional dict) derived from the dict class; in...

    python 3 inheritance Define a class named bidict (bidirectional dict) derived from the dict class; in addition to being a regular dictionary (using inheritance), it also defines an auxiliary/attribute dictionary that uses the bidict’s values as keys, associated to a set of the bidict’s keys (the keys associated with that value). Remember that multiple keys can associate to the same value, which is why we use a set: since keys are hashable (hashable = immutable) we can store them in...

  • they are 2 pictures attached 4) Delete set of keys from Python Dictionary Given: sampleDict =...

    they are 2 pictures attached 4) Delete set of keys from Python Dictionary Given: sampleDict = { "name": "Kelly", "age":25, "salary" : 8000, "city": "New york" } keysToRemove = ["name", "salary"] Expected output: {'city': 'New york', 'age': 25} 1) Write a Python program to iterate over dictionaries using for loops d = {'X': 10, y: 20, 'z': 30) 2) Write a Python program to get the maximum and minimum value in a dictionary my_dict = {'X':500, 'y':5874, 'z': 568} Sample...

  • 1. Pleae write the following code in Python 3. Also, please show all the outputs. ....

    1. Pleae write the following code in Python 3. Also, please show all the outputs. . Write a simple Rectangle class. It should do the following: Accepts length and width as parameters when creating a new instance Has a perimeter method that returns the perimeter of the rectangle Has an area method that returns the area of the rectangle Don't worry about coordinates or negative values, etc. Python provides several modules to allow you to easily extend some of the...

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

  • Python help: Given the lists, lst1 and lst2, create a new sorted list consisting of all...

    Python help: Given the lists, lst1 and lst2, create a new sorted list consisting of all the elements of lst1 that also appears in lst2. For example, if lst1 is [4, 3, 2, 6, 2] and lst2 is [1, 2, 4], then the new list would be [2, 2, 4]. Note that duplicate elements in lst1 that appear in lst2 are also duplicated in the new list. Associate the new list with the variable new_list, and don't forget to sort...

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