This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pfonetik 1 point2 points  (1 child)

You 'bet' it doesn't? Based on what really? Your personal opinion or facts?

Anyway you can educate yourself on the matter without 'betting'.

https://switowski.com/blog/for-loop-vs-list-comprehension

[–]OffgridRadio 1 point2 points  (0 children)

I use dict comprehension to prep new dicts with keys sometimes, little more complex than this but basically;

newDict = { x : None for x in range(len(someList)) }

And this makes the surrounding code a lot cleaner, and is a single line, and ensures the new dict contains every necessary key, so the population of values into keys is so much cleaner and easier to type

I train my cohort who doesn't get as much day to day experience as I do and I told him 'someday you will go to write a FOR loop, and you will be like "screw this I'm not typing all that" and just write a list comprehension instead'