Live data from Hacker News

Python built-ins worth learning

treyhunner.com

31–40 of 69 posts

Re: Python built-ins worth learning

#31
what was fascinating to me was how I fitted into the MUST SHOULD MAY MAYBE-NOT DONT matrix (in pseudo-normative form)

I used all but one of the MUSTS.

I used a few of the SHOULD

I used a similar few of the MAY

I only used one of the MAYBE-NOT (pow, and I am doing base arithmetic but not crypto)

I don't think I use any of the DONT

I'm interested in moving up on the SHOULD and MAY

Re: Python built-ins worth learning

#33

Earlier quoted context omitted.

It's really true. You can do a lot with data objects (dicts, lists) and stateless functions.

Rich Hickey has some nice talks about why separating the data from the methods is really beneficial.

There’s a great Python talk out there titled “Stop writing classes”. It has several great demonstrations of Python code getting shorter, simpler and faster by converting code to just use the built-in containers.

Re: Python built-ins worth learning

#35
post #5

> Many Python users rarely create classes. Creating classes isn’t an essential part of Python, though many types of programming require it. Huh. Okay.

while python is object oriented in the sense that everything is an object it doesn't insist of doing everything via message passing. It's quite happy with basic data types and simple functions (plus decorators and context managers)

Re: Python built-ins worth learning

#36

Earlier quoted context omitted.

Rich Hickey has some nice talks about why separating the data from the methods is really beneficial.

There’s a great Python talk out there titled “Stop writing classes”. It has several great demonstrations of Python code getting shorter, simpler and faster by converting code to just use the built-in containers.

I did like that talk very much - and here was my response:

> The Python Datamodel: When and how to write objects - https://www.youtube.com/watch?v=iGfggZqXmB0

Re: Python built-ins worth learning

#37
I am honestly a bit surprised divmod and complex are so high, I have only used them a couple of times myself - but I think they're almost always mentioned in "Intro to Python" books so most people should at least be familiar with them right?

Re: Python built-ins worth learning

#38
post #5

> Many Python users rarely create classes. Creating classes isn’t an essential part of Python, though many types of programming require it. Huh. Okay.

Data scientists for example.

Huh? Every data scientist I have worked with who writes production code uses classes.

Re: Python built-ins worth learning

#39
I always tend to recommend intermediate/advanced programmers to take a look at `functools` and `collections` packages - they are filled with amazing things that you haven't even though you need!

My favourites are `functools.partial`, `collections.Counter` and `collections.defaultdict` that are used very often by people who are aware of their existance.

Re: Python built-ins worth learning

#40

Sets are my #1 favourite Python built-in. I used to have these tedious imperative functions for doing change detection on collections. Then I learned sets and it turned into obvious code like: added = b - a removed = a - b repeated = a & b Etc. Of course this is set theory and not Python specific. But still. Learn sets!

frozenset is a really nice one for enforcing immutabolity :)
Post reply on HN