My stock dictionary has invalid syntax, why is that?


#1

Question

My stock dictionary has invalid syntax, why is that?

Answer

A common error when writing dictionaries is forgetting to add commas after each value except the last one in the dictionary. For example:

invalid_dictionary = {
  "key1" = 1
  "key2" = 2
  "key3" = 3
}

valid_dictionary = {
  "key1" = 1,
  "key2" = 2,
  "key3" = 3
}

FAQ: Learn Python – A Day at the Supermarket – Investing in Stock