this post was submitted on 17 Jan 2024
662 points (98.8% liked)

Programmer Humor

20829 readers
1294 users here now

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

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] Mastershelf@lemmy.one 10 points 1 year ago (3 children)

TIL Python dictionaries allow trailing commas.

[–] GBU_28@lemm.ee 5 points 1 year ago (1 children)
[–] dalegribble@beehaw.org 5 points 1 year ago (1 children)

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.

[–] Ephera@lemmy.ml 3 points 1 year ago (1 children)

Yeah, I think, that's only really JSON which is so pedantic about it...

[–] owenfromcanada@lemmy.world 3 points 1 year ago

Yeah...

sweats nervously in C

[–] renzev@lemmy.world 1 points 1 year ago

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