Ratings: 1 Star2 Stars3 Stars4 Stars5 Stars (5.00 out of 5) - Rate Now!

Download Category:

swapAndDictionary.zip - (54.47 KB)

1- 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 swapping
For 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’]
Try to do 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’
• Add 50 to the number stored under the ‘gold’ key.
• Print out the final dictionary

Get a fresh solution of this question. Ask it now to our experts.

Ask Your Question

We have verified professionals who are ready to answer your question.


Save Time and Money

We choose experts who can quickly answer your question and that suit your budget.


Get Your Answer

Your satisfaction is 100% guaranteed. You can keep on asking questions until you get the answer you need.