Write the program in python MythicalWorld is divided up into four different zones. In each zone there are three different pods of mythical beings. You are given two lists of the same length as...





Write the program in python


MythicalWorld is divided up into four different zones. In each zone there are three different pods of mythical beings. You are given two lists of the same length as follows:
mythicalPods = ["Fairies", "Elves", "Cyclops", "Unicorns", "Kelpie",


"Dragons", "Centaurs", "Sea Serpents", "Werewolf", "Sprites", "Loch Ness Monsters", "Manticore"] mythicalZones = [3, 3, 4, 2, 1, 4, 2, 1, 4, 3, 1, 2]

The list of zones contains the zone of each pod in the order as given in the pods list. For example, Fairies live in zone 3, Elves live in zone 3, Cyclops live in zone 4, etc. Given these two lists, sort the lists first based on the different zones (in ascending order) and then within each zone by the pod names (in ascending alphabetic order), by implementing the following two functions:




  •   function sortByZones that, given the lists, sorts the two lists based on the numeric order of the zones of the mythical pods (the mythical pods can be within any order in each zone after this function is complete)




  •   function sortByPods that, given the lists as sorted above, sorts the lists of mythical pods within the zones as well




  •   function main (given below) creates the two lists, prints the original lists, calls each of the functions, and displays the output after each function call. Note that all changes are to be done to the original list, even within the function calls. Save your code in a file called mythical_sort_fun.py.


    def main(): mythicalPods = ["Fairies", "Elves", "Cyclops", "Unicorns", "Kelpie", "Dragons", "Centaurs", "Sea Serpents", "Werewolf", "Sprites", "Loch Ness Monsters", "Manticore"] mythicalZones = [3, 3, 4, 2, 1, 4, 2, 1, 4, 3, 1, 2] print("Original list of Mythical Pods:") print(mythicalPods) print("Original list of Mythical Zones:") print(mythicalZones) sortByZones(mythicalPods, mythicalZones) print("\nPods sorted by their Zones only:") print(mythicalPods) print("Sorted Zones:") print(mythicalZones) sortByPods(mythicalPods, mythicalZones) print("\nPods sorted by their Zones and Pod Names:") print(mythicalPods) print("Sorted Zones:") print(mythicalZones)

    Sample output:


    Original list of Mythical Pods: ['Fairies', 'Elves', 'Cyclops', 'Unicorns', 'Kelpie', 'Dragons', 'Centaurs', 'Sea Serpents', 'Werewolf', 'Sprites', 'Loch Ness Monsters', 'Manticore'] Original list of Mythical Zones: [3, 3, 4, 2, 1, 4, 2, 1, 4, 3, 1, 2]

    Pods sorted by their Zones only: ['Kelpie', 'Sea Serpents', 'Loch Ness Monsters', 'Unicorns', 'Centaurs', 'Manticore', 'Fairies', 'Elves', 'Sprites', 'Werewolf', 'Cyclops', 'Dragons'] Sorted Zones: [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4] Pods sorted by their Zones and Pod Names: ['Kelpie', 'Loch Ness Monsters', 'Sea Serpents', 'Centaurs', 'Manticore', 'Unicorns', 'Elves', 'Fairies', 'Sprites', 'Cyclops', 'Dragons', 'Werewolf'] Sorted Zones: [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]






Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here