Quiz Catalog

Catalog of quizzes

d = {
  "fruits": 3,
  "vegetables": 5,
  "cherries": 2
}
p = d.keys()[:]
print(p)
TypeError: 'dict_keys' object is not subscriptable
  • dict/operation/keys

element_dict = {1: 4, "value": 20, "key": 1, 18: .9}
if any(element_dict):
  print(element_dict.keys())
dict_keys([1, 'value', 'key', 18])
  • dict/operation/keys
  • build-in/any

elements = {
  "key": "value",
  4: 20,
  "11": (1, 7, 2)
}

print(type(elements.keys()))
<class 'dict_keys'>
  • type
  • dict/operation/keys

car = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}

x = car.keys()

print(x)
dict_keys(['brand', 'model', 'year'])
  • dict/operation/keys

car = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}

x = car.keys()

car["color"] = "white"

print(x)
dict_keys(['brand', 'model', 'year', 'color'])
  • dict/operation/keys