You are viewing a single thread.
View all comments
11 points

TIL Python dictionaries allow trailing commas.

permalink
report
reply
1 point

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
permalink
report
parent
reply
3 points

Yeah, I think, that’s only really JSON which is so pedantic about it…

permalink
report
parent
reply
3 points

Yeah…

sweats nervously in C

permalink
report
parent
reply
5 points

List

permalink
report
parent
reply
5 points

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.

permalink
report
parent
reply
2 points

Yeh

permalink
report
parent
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 5.7K

    Monthly active users

  • 1.1K

    Posts

  • 40K

    Comments