Facebook
From Reajul Hasan Raju, 2 Weeks ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 194
  1. capitals = {
  2.     "Bangladesh": "Dhaka",
  3.     "India": "Delhi",
  4.     "USA": "Washington DC",
  5.     "Denmark": "Copenhagen",
  6.     "France": "Paris"
  7. }
  8.  
  9. # Accessing values using keys
  10. # print(f"The capital of USA is: {capitals['USA']}")
  11.  
  12. # Adding a new country and its capital
  13. # capitals['Australia'] = 'Canberra'
  14.  
  15. # Updating the capital of an existing country
  16. # capitals['India'] = 'New Delhi'
  17.  
  18. # Removing a country and its capital
  19. # del capitals['Bangladesh']
  20. # capitals.pop('Canada')
  21.  
  22. # Getting a list of all countries in the dictionary
  23. # countries = list(capitals.keys())
  24. # new_capitals = set(capitals.values())
  25. # print(new_capitals)
  26.  
  27. # Getting the number of key-value pairs
  28. # length = len(capitals)
  29.  
  30. # Using get() to retrieve the capital of a country
  31. # usa_capital = capitals.get('USA')
  32.  
  33. # Creating a copy of the dictionary
  34. # capitals_copy = capitals.copy()
  35.