Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Your linked stackoverflow question - how do you return the first item of the list or None.

Proposed solution - `a[0] if a else None`

Your reaction - Python doesn't offer a rich standard library.

I disagree, and I suspect most programmers would too. We'd much rather have ergonomic libraries to make http requests, parse command line arguments, datetime, itertools, data structures like heaps, filesystem access, data archiving, data serialization and deserialization and a million other nice-to-haves. It's actually at the point where I've heard criticism of Python's stdlib doing too many things, rather than too few.

If you don't want to write 19 characters to find the first item in a list, pick another language. But don't mischaracterise python's standard library.



> But don't mischaracterise python's standard library.

My main point is Ruby's stdlib is richer than Python's.

(And that's not either better or worse. Some people prefer lighter stdlib, and that's fine.)

> If you don't want to write 19 characters to find the first item in a list, pick another language.

Yes, if Python supported `.first`, I wouldn't want to write the longer version of it.

Since the article focuses on brevity, I did propose another language here, which was Ruby. It would serve better at how succinct a dynamic-typed language can be because of its richer stdlib, especially when we compare a dynamic-typed lang with Scala, which has an extremely rich stdlib. Using Ruby would be a fairer comparison.

I gave one small example (`.first` vs `a[0] if a else None`) to illustrate my claim. Two more examples (from https://ruby-doc.org/core-2.4.1/Array.html) are `.rotate` and `.transpose`. I'm sure there are more examples around Hash and other data structures.

Python don't have these methods, and we have to make them ourselves. To make code even longer, we need to maintain and write unit tests on them.


I have also found Python’s stdlib to be laughably bad. Just compare the data structures available to Scala. I write Python everyday and honestly, it’s a chore. The language is primitive and inexpressive.

The sad part is that it totally didn’t have to be this way. But instead of evolving, Python is just stuck in the past.


Could you point to some specific examples?


Here was one example I encountered a while back: https://stackoverflow.com/questions/952914/how-to-make-a-fla...

In Python, it's `import itertools` and `list(itertools.chain.from_iterable(list2d))` or `[item for sublist in list2d for item in sublist]`. In Scala, it is `list2d.flatten`.

In fact, Python is against making a richer stdlib in general.

"It has been discussed ad nauseam on comp.lang.python. People seem to enjoy writing their own versions of flatten more than finding legitimate use cases that don't already have trivial solutions." from https://softwareengineering.stackexchange.com/questions/2542...

And, intuitively, when you don't want to provide a helper function, the user code gets longer.

Not that this is better or worse. It's just that, specifically, on the brevity aspect, Python code would generally becomes longer. Because, as you see in the quote, "People seem to enjoy writing their own versions of flatten".


Python has Lists (arrays), Dict, and Sets. That's pretty much it.

There's no linked lists. There's no sorted maps, no sorted sets, no maps that preserve insertion order, no queues, no priority queues, no bitsets. And there's no immutable collection in Python besides strings.

Meanwhile, Scala has all of that and more: https://docs.scala-lang.org/overviews/collections/overview.h...

Moreover, scala has synchronized collections that can work over multiple threads. I guess all collections work that way in Python, but that's because Python doesn't even support true thread parallelism in the first place!

Also, if we're talking about the number of methods on the collections, Scala has way way more. map/foreach/filter/foldl/foldr/option/drop/take/first/last etc etc.


> And there's no immutable collection in Python besides strings

frozensets, tuples?




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: