HNHacker News
TopNewBestAskShowJobs

raymondh

2,430 karma · joined February 9, 2010

Highlights:

  * CEO of Mutable Minds, Inc. (a training and consulting company)
  * Python Distinguished Service Award
  * Past Python Software Foundation (PSF) board member
  * Private pilot (single engine land and sailplanes)
  * Certified Public Accountant
  * Certified Internal Auditor
  * Python Core Developer
  * Husband to Rachel
  * Father to Matthew
Python training video series, "Modern Python: Big Ideas, Little Code" available for free to Safari On-line subscribers: https://www.oreilly.com/library/view/modern-python-livelessons/9780134743400/

Videos for conference presentations and keynotes can be found at: https://www.youtube.com/playlist?list=PLRVdut2KPAguz3xcd22i_o_onnmDKj3MA

Contributions to Python:

  * any()
  * all()
  * enumerate()
  * local mapping argument to exec() can be any mapping
  * filter() -- originally itertools.ifilter
  * frozenset()
  * map() -- originally itertools.imap
  * reversed()
  * sum() -- optimized and made more accurate
  * zip() -- originally itertools.izip
  * sorted()
  * set()
  * dict.fromkeys
  * dict.pop
  * float.as_integer_ratio
  * str.format_map
  * str.partition
  * str.rpartition
  * tuple.count
  * tuple.index
  * abc.ABC
  * antigravity.geohash 
  * bisect module -- key function support
  * calendar module -- various fixups
  * collections.ChainMap
  * collections.Counter
  * collections.OrderedDict
  * collections.deque
  * collections.namedtuple
  * contextlib.redirect_stderr
  * contextlib.redirect_stdout
  * contextlib.suppress
  * decimal module
  * difflib.context_diff
  * difflib.unified_diff
  * fractions.limit_denominator -- with Mark Dickinson
  * functools.cache
  * functools.cmp_to_key
  * functools.lru_cache
  * functools.total_ordering
  * heapq.heappushpop
  * heapq.merge
  * heapq.nlargest
  * heapq.nsmallest
  * itertools.accumulate
  * itertools.chain
  * itertools.chain.from_iterable
  * itertools.combinations
  * itertools.combinations_with_replacement
  * itertools.compress
  * itertools.count
  * itertools.cycle
  * itertools.dropwhile
  * itertools.filterfalse
  * itertools.groupby
  * itertools.islice
  * itertools.pairwise
  * itertools.permutations
  * itertools.product
  * itertools.repeat
  * itertools.starmap
  * itertools.takewhile
  * itertools.tee
  * itertools.zip_longest
  * json.AttrDict (later removed)
  * math.dist
  * math.fsum -- with Mark Dickinson
  * math.hypot -- improve algorithm and expanded to n-dimensional case
  * math.log -- added the "base" optional argument
  * math.prod -- implemented by Pablo Galindo
  * operator.attrgetter
  * operator.itemgetter
  * queue.LifoQueue
  * queue.PriorityQueue
  * queue.join
  * queue.task_done
  * random's MersenneTwister
  * random.SystemRandom
  * random._randbelow
  * random.binomialvariate
  * random.choices
  * random.sample
  * random.triangular
  * statistics.correlation -- added spearman rank correlation coefficient
  * statistics.fmean
  * statistics.geometric_mean
  * statistics.harmonic_mean -- added weights parameter
  * statistics.kde
  * statistics.kde_random
  * statistics.linear_regression -- added direct proportion option
  * statistics.mode -- fixed api
  * statistics.multimode
  * statistics.NormalDist
  * statistics.quantiles
  * statistics.variance/pvariance/stdev/pstdev -- correctly ounded
  * tokenize.untokenize
  * userdict.DictMixin -- eventually became ollections.MutableMapping
  * __slots__ can be a dictionary
Designer of:

  * key-functions
  * generator expressions
  * compact and ordered dictionaries
  * the peephole optimizer
  * __length_hint__ optimization
  * the thousands separator in string formatting
  * original proponent of exception chaining
  * original proponent of sending data and exceptions into enerators
  * eval-loop opcode prediction
Maintainer of:

  * the argparse module (successor to Steven Bethard)
  * the bisect module
  * the collections module
  * the collections.abc module
  * the decimal module
  * the heapq module
  * the itertools module
  * the queue module
  * the random module
  * the statistics module (with Steven D'Aprano) 
Author of:

  * Python How-to: Descriptor Guide
  * Python How-to: Sorting Techniques
  * Python tutorial: Looping Techniques
  * Python tutorial: Tour of the standard library
  * Python tutorial: Floating Point Arithmetic
  * Blog post: Super Considered Super
  * Whatsnew 3.1
  * Whatsnew 3.2
  * Whatsnew 3.8
Social media:

  * https://twitter.com/raymondh
  * https://rhettinger.wordpress.com/
  * https://www.facebook.com/raymondh
  * https://www.linkedin.com/in/raymondhettinger/
  * https://stackoverflow.com/users/1001643/raymond-hettinger
submissionscomments
raymondh··on Reasons Python Sucks (2018)
Indeed, this list is better.
raymondh··on Reasons Python Sucks (2018)
Nope.
raymondh··on Sesame allergen labeling law has unintended effect: sesame in more foods
Summary: A new law substantially increases liability for making a sesame free product. The predictable result was that there are now fewer sesame free products. Now, everyone is worse off.
raymondh··on “News is what somebody does not want you to print – all the rest is advertising”
The title is THE most accurate summary of the content.
raymondh··on CircleCI Layoffs
For those of you unfamiliar with layoff practices in most other industries, this is as good as it gets. The terms enumerated in the note are generous. Also, the value of the job placement support should not be underestimated.
raymondh··on A homework question in someone’s 11th grade statistics class
I think Feynman would be pleased with question. He was well grounded in the real world of doing science with incomplete datasets. For researchers who gather data with surveys, this is a frequently encountered problem, so it is legitimate to discuss it an statistics course.

If there is a problem, it is the multiple choice format. This issue of handling incomplete datasets would be make a good essay question.

That said, it is perfectly reasonable to choose D and work with the information you have. That is what real world clinic studies do when they report the number of people who dropped out of a study.

It is also reasonable to choose A and attempt to get better coverage. That is what real world election pollsters do.

raymondh··on CORDIC
Here's a simple Python implementation:

https://code.activestate.com/recipes/576792-polar-to-rectang...

raymondh··on NASA’s Webb takes star-filled portrait of Pillars of Creation
Thank you.
raymondh··on Mathematicians discover the Fibonacci numbers hiding in strange spaces
There is a carry from the 5+8=13.

Add these up and you get closer and closer to 1 / 89:

    0.0
    0.01
    0.001
    0.0002
    0.00003
    0.000005
    0.0000008
    0.00000013
    0.000000021
    0.0000000034
    0.00000000055
    0.000000000089
    0.0000000000144
    0.00000000000233
    0.000000000000377
    0.0000000000000610
    0.00000000000000987
    0.000000000000001597
    0.0000000000000002584
    0.00000000000000004181
    0.000000000000000006765
    0.0000000000000000010946
    0.00000000000000000017711
    0.000000000000000000028657
    0.0000000000000000000046368
    0.00000000000000000000075025
    0.000000000000000000000121393
    0.0000000000000000000000196418
    0.00000000000000000000000317811
    0.000000000000000000000000514229
    0.0000000000000000000000000832040
    0.00000000000000000000000001346269
    0.000000000000000000000000002178309
    0.0000000000000000000000000003524578
    0.00000000000000000000000000005702887
    0.000000000000000000000000000009227465
    0.0000000000000000000000000000014930352
    0.00000000000000000000000000000024157817
    0.000000000000000000000000000000039088169
    0.0000000000000000000000000000000063245986
    0.00000000000000000000000000000000102334155
    0.000000000000000000000000000000000165580141
    0.0000000000000000000000000000000000267914296
    0.00000000000000000000000000000000000433494437
    0.000000000000000000000000000000000000701408733
    0.0000000000000000000000000000000000001134903170
    0.00000000000000000000000000000000000001836311903
    0.000000000000000000000000000000000000002971215073
    0.0000000000000000000000000000000000000004807526976
    0.00000000000000000000000000000000000000007778742049
    0.000000000000000000000000000000000000000012586269025
    0.0000000000000000000000000000000000000000020365011074
    0.00000000000000000000000000000000000000000032951280099
    0.000000000000000000000000000000000000000000053316291173
    0.0000000000000000000000000000000000000000000086267571272
    0.00000000000000000000000000000000000000000000139583862445
    0.000000000000000000000000000000000000000000000225851433717
    0.0000000000000000000000000000000000000000000000365435296162
    0.00000000000000000000000000000000000000000000000591286729879
 +  0.000000000000000000000000000000000000000000000000956722026041
    --------------------------------------------------------------
    0.011235955056179775280898876404494382022471910112174867308031 ≈ 1 / 89
    ==============================================================

For those interested in running this with more iterations, here is a Python script:

    from decimal import *
    
    n = 60

    getcontext().prec = n
    t = Decimal(0)
    p, q = 0, 1
    for i in range(1, n+1):
        s = f'0.{p:0{i}}'
        print(s)
        t += Decimal(s)
        p, q = q, p+q
    print('-' * (n + 2))  
    print(t, '≈ 1 / 89')
    print('=' * (n + 2))
    print()
    print(1 / t)
raymondh··on Mathematicians discover the Fibonacci numbers hiding in strange spaces
My ten year old found Fibonacci numbers in the reciprocal of 89.
raymondh··on Ask HN: How do you keep up with AI advances, esp. Stable Diffusion and GPT-3?
If it weren't for Hacker News, I wouldn't have a chance to keep up with the new progress.
raymondh··on Guido was right, there should be no lambda in Python (2018)
It does. Just add parentheses.
raymondh··on Guido was right, there should be no lambda in Python (2018)
Python's lambda is powerful enough to write a Y-combinator:

https://twitter.com/raymondh/status/1352018456401440769

raymondh··on The Scourge of Rent Control
Presumably, there is even more pain in the world of rent control. By definition, a submarket rate apartment has a supply/demand imbalance.

There is someone who values the apartment more than you do who can't live there, perhaps denying them the chance to be closer to their job or family. Also, you have less economic incentive to take in a roommate, thus denying another category of potential occupant.

In a rent control system, there are winners and losers. I'm happy that it has worked out well for you, but the survivor bias needs to be pointed out.

raymondh··on Someone’s Been Messing with My Subnormals
This is a rockstar quality post. It is astonishing how much detective work was involved.
raymondh··on A third of Pakistan is underwater from floods, climate chief says
WaPo leans heavily toward fitting the news to its narratives and is generally terrible with data science.

Whether and to what extent these 5 unlikely events is an anomaly depends on the number of measurement locations and the expected year-to-year variability. If there were 5,000 reporting sites, would we be surprised by "5 different 1-in-1000 year flooding events" in one year?

Climate change is real, but so are enthymemes and low quality news reporting.

raymondh··on AWS services, explained in Victorian English with GPT-3
This is priceless.
raymondh··on The effects of grounding on inflammation
I use copper cookware and I feel great.
raymondh··on Speech by Chair Powell on monetary policy and price stability
Excellent analysis.
raymondh··on From Roots to Polynomials
Nice work on this post. It was easy to follow your line of exploration and thinking. May I suggest a couple of simplifications.

The generator expression in the sum() just applies a one-argument function so it can be replaced with map(). And instead of computing a sign at each step, it is simpler and faster to negate the roots at the outset.

There actually is a combinations(..., 0) in Python, and it returns [()] which is consistent with math.comb(4, 0) returning 1. Also, prod([]) returns 1. Putting those facts together helps eliminate special case at the end point.

Here's the simplified code:

    from itertools import combinations
    from operator import neg
    from math import prod

    def coeffs_from_roots(roots):
        roots = list(map(neg, roots))
        return [
            sum(map(prod, combinations(roots, k)))
            for k in range(len(roots) + 1)
        ]
raymondh··on High property taxes are good
My experience of high property taxes is that it no longer feels like you own a home. You pay rent on it forever. At any time the rent can rise to more than you can afford. I own my home outright but likely won't be able to stay when I retire.
raymondh··on New numbers on music consumption
It is also measurement bias in choosing what to pay attention too. The content of high budget films makes for a poor metric for creative output.

High budget films inherently have huge financial risk, so it reasonable that the decision making is risk adverse. Meanwhile, the rest of the ecosystem is flourishing with creativity. We have an astonishing selection of works in indie films, HBO, and Netflix programming. As a consumer, I've never had more high quality options to choose from.

Hollywood of old used to crank out and an enormous number of films, almost none of which were big budget. This is the same as today where streaming services crank out an enormous number of creative entertainment options.

The oligopolies of recent years may find that their business models are challenged, but the industry as a whole hasn't lost an ounce of creativity.

raymondh··on Covid-19 vaccine doses, once in high demand, now thrown away
Also, it's inevitable that the virus will adapt our best antiviral, Paxovid.

https://www.science.org/content/article/bad-news-paxlovid-co...

raymondh··on WTFPython: Exploring and understanding Python through surprising snippets
Fair enough :-)
raymondh··on WTFPython: Exploring and understanding Python through surprising snippets
IMHO this is one of the worst ways to improve your Python skills. Instead, focus on what the normal, robust, beautiful, clear, and idiomatic solutions to problems.

There is an enormous amount of quality training material available as well as excellent source code to major projects.

Most people would be better off just spending a hour or so with the tutorial at docs.python.org.

I get people coming to me asking for a job teaching Python when they don't know of some the material in the tutorial. Most have never read the FAQs and aren't aware of common solutions to common problems. To me, if you want to build your skills, start there. Get in the habit of reading docs, even boring ones, and occasionally read some of the source code from your favorite libraries.

That said, if you've already a very strong Python programmer, one possible use for these snippets is to help you root out any last, misconceptions of minor details.

But, you should resist the urge to show-off or use almost any of these "skills". There are a lot of cute things we can do with chained comparisons, but the only sensible things are: lo <= x <= hi or f(x) == g(x) == h(x). Anything else is too weird for communicating with the human beings. Likewise, you should only use "is" for None tests until you have strong understanding of identity guarantees.

raymondh··on A maximally-dense encoding for n-choose-k (2013)
For those who want to explore these ideas in Python, see the nth_combination() and random_combination() recipes in the itertools docs¹ or just install them from more-itertools².

    # Find the 48,001st combination from 32 choose 8
    >>> nth_combination(range(32), 8, 48000)
    (0, 1, 2, 5, 11, 21, 27, 28)
¹ https://docs.python.org/3/library/itertools.html#module-iter... ² https://more-itertools.readthedocs.io/en/stable/
raymondh··on Multiple assignment and tuple unpacking improve Python code readability (2018)
It was, but that is not guaranteed and may stop being true due to work on subinterpreters, new memory managers, and heap types.

Also, it used to be true that ``frozenset() is frozenset()``, but that was lost in the war on singletons and global state.

raymondh··on Multiple assignment and tuple unpacking improve Python code readability (2018)
Yes, that would be correct.

   a = b = 10       # multiple assignment

   a, b = b, a      # simultaneous (or parallel) assignment
raymondh··on Emerging evidence that mindfulness can sometimes increase selfish tendencies
Over my career, I've also seen some variations of this theme.

A group of experienced, task-saturated senior auditors were pulled in from the field to attend an anti-stress seminar. During the guided meditation, an intense but non-destructive earthquake hit (in a high-rise building in downtown Los Angeles). It was the auditors who kept their wits and made clear decisions to calmly exit the structure. In marked contrast, the stress-reduction instructors were a wreck.

A friend and I used to go out to eat on a regular basis. He reasonably decided to change his diet to more healthy foods. For all I know, it did improve his health, but I did observe that at a ball game, he opted for a hamburger and then his body rebelled. He had lost the ability to eat commonplace foods.

Among meditators (of which I was one), I observed a heighten sensitivity to being knocked off kilter by anything or anyone that conflicted with the world view of the practitioner.

My friends who were into body building routinely lifted weights for many hours a week, but when suitcases or scuba tanks need to be carried, there a was strong aversion. I surmised that the unbalanced loads greatly threw-off how they had trained themselves to lift weights with good form.

Among Python programmers who use Black and isort in order to improve the appearance of code, it is common to become intolerant of code that they used to consider perfectly readable. Likewise, it is common to become highly judgmental of people who don't use that tooling (and even more so with type annotations where proponents seem to have an almost religious fervor).

I don't really know what conclusion to draw from these events, but there is something of interest going on.

raymondh··on Multiple assignment and tuple unpacking improve Python code readability (2018)
Roughly, that is true. However, the actual pattern matching rules are a bit more complex:

   ()          # Makes a zero-tuple. The parens are required.

   2,          # Makes a one-tuple.
   (2,)        # Makes a one-tuple. The parens are optional.

   [2]         # Makes a list of size one.
   [(2)]       # Also makes a list of size one.
   [2,]        # Also makes a list of size one.

   f(x, y)     # Call a function with two arguments.
   f((x, y))   # Make a 2-tuple and call a function with one argument.
← PreviousPage 2 of 11Next →