Use this TRICK on #python lists

preview_player
Показать описание
#pythonprogramming #coding

Code editor: VSCode
Рекомендации по теме
Комментарии
Автор

There is another reason. This feature goes from C. It is easier to generate code for lists, enums, etc. One may always print comma in the end and not have headache about removing trailing comma.

danielmilyutin
Автор

Yup, this happens to me all the time. And I'll waste a good 5 mins trying to figure out where my syntax went wrong. Good habit to have the trailing comma,

sweealamak
Автор

I do this all the time. Not doing it is basically asking for your code to break if you often manipulate a lot of lists over time. It's especially useful in config files that might get messed with a lot, like in Qtile.

Nukelover
Автор

I do this in JavaScript too. Prettier has an option of adding trailing commas for you.

bgill
Автор

If I was reviewing a pull request that had this, I would probably think that an item was meant to be present after that comma since I wasn’t familiar with the syntax. Also, I don’t really think the 2-line CS 1-line diff thing is too big a deal. This was something I had never seen though, so thank you for sharing it!

BbB-vruh
Автор

In most programming languages, you can effectively accomplish the same by just placing the comma before each item after the first. Like:
“A”
, ”B”
, ”C”

As long as any new item you add is not entered at the first position in the list, only 1 line is updated in the diff per item added.

_Painted
Автор

I always prefered not to have a trailing comma before but you convinced me

leokillerable
Автор

I have always wondered if it could be in any way a future problem for the security of our app, letting that extra comma.

angelgomez
Автор

I have multiple excel worksheets with multiple worksheets/tabs. I want to merge these tabs into one summary excel worksheet. Any quick python script that can help me get the multiple Excell spreadsheet with multiple worksheets in to one summary. Thanks for another great video. Keep sending us the tricks. Thanks

khalidjj
Автор

The fundamental question on this is

“Is this truly Pythonic or not?” 🤔

tigerbojiteol
Автор

Tbh. I thought it was against the syntax.

pwrdprompt
Автор

If you ducking do this in js or forget a comma in js it's gonna blast your pc with 56 warnings

tushar_bajpai
Автор

I like the premise, but if you code in multiple languages frequently, That would be confusing as hell having to convert every time.

rodbotic
Автор

Is there even a use case for not having a comma?

daze
Автор

I knew it, but I didn't know the usage. I thought that the comma in the last item of a list was just permited by python to avoid an error of exactly collocating a comma at the end of the last item of the list. 😂

fernandoduarte
Автор

curious how did you open up another code window?

alyx
Автор

Doesn't it affect the length of the list? Just a question

patrickman
Автор

Why does python not have compile time errors so annoying

urisinger
Автор

Another reason python sucks. Who thought implicit concatenation was a good idea?

redcrafterlppa
Автор

You lost me at diff. That’s why I’ve asked you in many streams to do one on git 😢

Ashraf.elgaaly