0

in this code

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

x = car.get("model")

the answer will be Mustang is quite simple but I'm confused when is applied to key like in this code

scores = {leaf_size: get_mae(leaf_size, train_X, val_X, train_y, val_y) for leaf_size in candidate_max_leaf_nodes}
best_tree_size = min(scores, key=scores.get)

here you want the minimum values but show the corresponding key why then they didn't use key=scores.values ?

  • 1
    `min` will call for each `score_key`: `scores.get(score_key)` – Peter Wood Oct 03 '21 at 22:33
  • key specifies a function of one argument that is used to extract a comparison key from each list element. https://docs.python.org/3/library/functions.html#min – Arvind Oct 03 '21 at 22:35

0 Answers0