[Tutor] reason(s) for trailing comma in dict declarations

akleider at sonic.net akleider at sonic.net
Sat Aug 25 17:53:54 CEST 2012


Part of a previous post:
"""
Here's the style I'd use:

combos = {
  0: 'id',
  2: 'country',
  3: 'type',
  5: 'lat',
  6: 'lon',
  12: 'name',
}

Put each entry on its own line, indented by two spaces, and leave a
trailing comma on the last entry. The latter is especially important
in sequences of strings to prevent them from being
"silently"<=>"concatenated" if you were to add an entry and forget the
comma.
"""

When I first saw this I thought it would lead to a syntax error so tried
it out..
Then played with it to try to recreate the '"silently"<=>"concatenated"'
problem but couldn't.  I like this syntax because it avoids the syntax
error if the comma is omitted when adding an entry but I don't understand
the (potential) concatenation problem.

Could you explain please?
alex



More information about the Tutor mailing list