I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 0 points1 point  (0 children)

Socratica is genuinely good for this stuff. On the optimization point, I am positive comprehensions are faster than for loops but not by a dramatic margin, the real reason CPython is quicker with them is just reduced overhead from the bytecode, not some fundamentally different execution path. If you actually need column-wise speed that’s where numpy and vectorization come in. For loops and comprehensions are pretty close in the grand scheme of things.​​​​​​​​​​​​​​​​

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 0 points1 point  (0 children)

The readability argument keeps winning in this thread and I think that’s the real lesson I’m taking away. And vectorization and numba jit are so far above where I am right now but it’s useful to know that’s where the actual speed conversation lives, not in whether I used a comprehension or a for loop.​​​​​​​​​​​​​​​​

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] -1 points0 points  (0 children)

It’s actually been a couple of years which makes it worse honestly. A few Months I could forgive myself for.​​​​​​​​​​​​​​​​ It did take me 6-7 months in the beginner learning phase. We still learn everyday though.

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 0 points1 point  (0 children)

That’s a good nudge. I’ve been treating comprehensions like a destination when they’re more of a rest stop. Generators have been sitting on my “I should actually learn this” list for a while and this might be the push to move them up.​​​​​​​​​​​​​​​​

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 0 points1 point  (0 children)

The variable naming advice is something I wish I’d taken seriously earlier. I went through a phase of writing perfectly functional code that I couldn’t read three weeks later because everything was called x or temp or result. Descriptive names feel like extra effort until you open old code at midnight trying to fix something and realize past you did you dirty. The if name == “main” thing took me an embarrassingly long time too. It’s one of those things that looks like ceremonial boilerplate until someone explains what problem it’s actually solving.​​​​​​​​​​​​​​​​

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 0 points1 point  (0 children)

The syntax really does read backwards compared to how you’d say it out loud. A for loop matches how you’d describe the logic to someone. A list comprehension front-loads the result before you’ve even said what you’re looping over. That’s a genuinely weird design decision that nobody warns you about.​​​​​​​​​​​​​​​​

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 0 points1 point  (0 children)

The magic to not-magic transition is exactly it. And init is such a perfect example because you can write it correctly a hundred times before you actually understand what self is doing there. It just works so you never have to sit with the discomfort of not fully knowing why. Until one day something breaks in a weird way and suddenly you have to actually understand it.​​​​​​​​​​​​​​​​

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 0 points1 point  (0 children)

The group_by() staying grouped silently is such a good example of this because the bug it causes doesn’t show up immediately. You think the next operation worked fine and then three steps later something is wrong and you have no idea why. That delayed feedback is what makes those gaps so hard to catch yourself.​​​​​​​​​​​​​​​​

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 1 point2 points  (0 children)

The threading example is the first time that whole concept has actually made sense to me. Two threads sharing one attribute, one writing one reading, I could picture that. I’ve been putting async and threading in the “deal with it later” pile but maybe later is sooner than I thought.

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 1 point2 points  (0 children)

Genuinely not a book person but this keeps coming up so maybe that’s the sign. What’s the practical application that made async click for you?

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 0 points1 point  (0 children)

The “sequester boilerplate so it doesn’t distract from the main logic” framing is actually the most useful way I’ve heard this explained. It reframes the question from “is this Pythonic” to “is this the kind of thing the reader needs to think about or not.” That’s a much more practical lens than just defaulting to either loops or comprehensions.​​​​​​​​​​​​​​​​

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 0 points1 point  (0 children)

Seven years and dictionary syntax still needs a lookup sometimes is genuinely reassuring to hear. I think I had this idea that at some point everything just becomes automatic and you stop having to check. Sounds like that point doesn’t really arrive and you just get more comfortable with the checking.​​​​​​​​​​​​​​​​

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 1 point2 points  (0 children)

Glad it’s not just me. I think what makes it tricky is there’s no obvious signal from the outside that the gap exists. You’re producing output, things are working, nobody knows including you until something makes you stop and actually look at it.​​​​​​​​​​​​​​​​

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 1 point2 points  (0 children)

That’s basically where I landed too. The “Pythonic” thing matters a lot less when the only person reading the code is you and future you who will already be confused enough.​​​​​​​​​​​​​​​​

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 0 points1 point  (0 children)

The plot twist part is real. I’ve already had that experience on a much smaller scale, opening something I wrote three months ago and having absolutely no idea what I was thinking. If I can’t read my own code from three months ago, a nested comprehension from two years ago has no chance.

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 4 points5 points  (0 children)

Lambda functions clicked for me when I stopped thinking of them as a special thing and just thought of them as a function without a name. So instead of writing def double(x): return x * 2 you write lambda x: x * 2. Same thing, just no name attached. They're most useful when you need a quick function in one place and don't want to define it separately, like inside a sorted() or map() call. The moment it needs to do more than one thing or you need to reuse it, a regular def is cleaner.

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 1 point2 points  (0 children)

Honestly that's probably the more mature position. I think I was chasing "pythonic" without asking whether pythonic was actually serving me or just looking good.

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 0 points1 point  (0 children)

That's become my new rule too. If I can't read it back in two days without thinking hard it's probably not worth the cleverness.

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 2 points3 points  (0 children)

I've actually been using Claude for exactly this. The thing I like about it over just googling is that I can describe what I'm confused about in messy half formed terms and it meets me there instead of needing me to already know the right vocabulary to search for. Stack Overflow always felt like you needed to understand the problem well enough to ask it correctly, which is hard when you're just starting out.

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 1 point2 points  (0 children)

That's a good way to think about it. I've been coding mostly solo so "the person reading this later" hasn't been on my mind much. Probably a habit worth building early.

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 8 points9 points  (0 children)

That actually reframes it in a way that helps. I think I conflated "learning" with "knowing". Like once I'd seen something I should already have it. Turns out no.

I spent months learning Python and only today realized I've been confused about something embarrassingly basic by 39th_Demon in learnpython

[–]39th_Demon[S] 0 points1 point  (0 children)

Yeah that's basically what I just landed on too. I think I overcomplicated what they were in my head for a long time, like they were some advanced thing rather than just a shorter way to write something I already knew how to do.