Write a python function

Click Here to Download this Answer Instantly


Write a python function called swap_on_demand(list1, ind1, list2, ind2). The function is supposed to take four inputs list1, ind1, list2, ind2. Your function is supposed to swap the element that has index ind1 in list1 with the element that has ind2 in list2 then print out both lists after swappingFor example, (you can also use the example to test out your function):
If I define pets=[‘cats’, ‘dogs’, ‘shark’,’fish’] and
birds = [‘canary’, ‘parrot’, ‘cockatoo’,’lovebird’]Calling your function as swap_on_demand(pets, 2, birds, 1) should result in the following prints statements
[‘cats’, ‘dogs’, ‘parrot’,’fish’]
[‘canary’, ‘shark’, ‘cockatoo’,’lovebird’]2. Given the following dictionary:inventory = {
‘gold’ : 500,
‘pouch’ : [‘flint’, ‘twine’, ‘gemstone’],
‘backpack’ : [‘xylophone’,’dagger’, ‘bedroll’,’bread loaf’]
}o the followings:
• Add a key to inventory called ‘pocket’.
• Set the value of ‘pocket’ to be a list consisting of the strings ‘seashell’,
‘strange berry’, and ‘lint’
.sort() the items in the list stored under the ‘backpack’ key.
• Then .remove(‘dagger’) from the list of items stored under the ‘backpack’ key.
• Add 50 to the number stored under the ‘gold’ key.
• Print out the final dictionary