The Perfect Solution

JPDev@programming.dev to Programmer Humor@programming.dev – 676 points –
81

You are viewing a single comment

TIL Python dictionaries allow trailing commas.

List

While there are not actually any trailing commas in the dictionaries present and you are correct to say the ones present are part of a list, you can also have trailing commas in Python dictionaries. OP might have researched “Python trailing commas” and learned that part.

Trailing commas are fantastic to reduce changed lines in git diffs. Makes life much better. Same thing with leading commas in SQL queries.

Python is so great (half-sarcasm) that a trailing comma on its own constitutes a tuple (immutable list):

mytuple = 4,
assert len(mytuple) == 1
assert mytuple[0] == 4