akosiraff

Download swapAndDictionary Answer

Oct 28th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1.  
  2. Download: https://solutionzip.com/downloads/swapanddictionary/
  3. 1- Write a python function called swap_on_demand(list1, ind1, list2, ind2). The function
  4. is supposed to take four inputs list1, ind1, list2, ind2. Your function is supposed to
  5. swap the element that has index ind1 in list1 with the element that has ind2 in list2 then
  6. print out both lists after swapping
  7. For example, (you can also use the example to test out your function):
  8. If I define pets=[‘cats’, ‘dogs’, ‘shark’,’fish’] and
  9. birds = [‘canary’, ‘parrot’, ‘cockatoo’,’lovebird’]
  10. Calling your function as swap_on_demand(pets, 2, birds, 1) should result in the
  11. following prints statements
  12. [‘cats’, ‘dogs’, ‘parrot’,’fish’]
  13. [‘canary’, ‘shark’, ‘cockatoo’,’lovebird’]
  14. 2- Given the following dictionary:
  15. inventory = {
  16. ‘gold’ : 500,
  17. ‘pouch’ : [‘flint’, ‘twine’, ‘gemstone’],
  18. ‘backpack’ : [‘xylophone’,’dagger’, ‘bedroll’,’bread loaf’]
  19. }
  20. Try to do the followings:
  21. • Add a key to inventory called ‘pocket’.
  22. • Set the value of ‘pocket’ to be a list consisting of the strings ‘seashell’,
  23. ‘strange berry’, and ‘lint’.
  24. • .sort()the items in the list stored under the ‘backpack’ key.
  25. • Then .remove(‘dagger’) from the list of items stored under the ‘backpack’
  26. key.
  27. • Add 50 to the number stored under the ‘gold’ key.
  28. • Print out the final dictionary
  29. Download: https://solutionzip.com/downloads/swapanddictionary/
Add Comment
Please, Sign In to add comment