Raymond Hettinger Profile
Raymond Hettinger

@raymondh

Followers
75K
Following
4K
Media
77
Statuses
6K

Chief trainer for Mutable Minds. Certified Public Accountant, Retired Python guru. Alloy & TLA⁺ enthusiast. Aspiring pianist. Former pilot. Born at 320 ppm CO₂.

Austin, TX
Joined March 2008
Don't wanna be here? Send us removal request.
@raymondh
Raymond Hettinger
1 year
#Python tip: If you were to devote a little effort into mastering just one itertool, it should be islice(). Its motivation was to be an analogue of sequence slicing but with next-in-a-loop as the foundation rather than __getitem__() and __len__().
3
11
149
@raymondh
Raymond Hettinger
3 months
QOTD: "There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies." -- C.A.R. Hoare
2
6
47
@raymondh
Raymond Hettinger
3 months
#Python notes: imap_unordered() has less overhead than imap() and map(). Calls to imap and map do not yield results immediately. Instead, they buffer results in memory until the ordering and completion requirements are met. This eats memory and impairs responsiveness.
1
2
35
@raymondh
Raymond Hettinger
4 months
Often it is the most basic questions that are the hardest to answer. * What is a number? * What is a straight-line? * What do you mean by "continuous"? * What is "red"? * What is "attention"? * When is something "conscious"? * What is "casual"?
7
2
44
@raymondh
Raymond Hettinger
4 months
#Python / C tip: Replace log(1 + x) or log(1 - x) with log1p(x) or log1p(-x). Avoiding an unnecessary addition or subtraction saves work. More importantly, it avoids loss of significance *prior* to making the log/log1p call.
0
2
44
@pwang
Peter Wang 🦋
5 months
*raises hand* There are dozens of us! DOZENS!!
@ID_AA_Carmack
John Carmack
5 months
I like em dashes, and I hate that some people now take them as evidence of text being AI generated.
1
7
45
@raymondh
Raymond Hettinger
5 months
In your experience, are LLMs as vulnerable as humans to be thrown-off by incorrect code comments?
6
2
17
@raymondh
Raymond Hettinger
6 months
#Python notes: The Counter in the collections module supports two kinds of arithmetic. The update() and subtract() methods implement normal arithmetic with possible negative numbers in the results. The "+" and "-" implement saturating arithmetic giving non-negative results.
1
1
28
@raymondh
Raymond Hettinger
6 months
#Python teaching tool: To demonstrate testing and debugging, I often use this function: def square(n: int) -> int: return sum(n - 2 for i in range(n + 2)) + 4 Tests pass for n=100, n=7, n=1, n=0, n=-1, and n=-2. But fail for n=-5. Tests can't prove the absence of errors.
1
6
43
@raymondh
Raymond Hettinger
6 months
#Python teaching tip: If someone says, "I didn't get topic X, can you go over it again" that means that your approach wasn't successful. Don't say the same words over again. Instead, approach the topic from a completely different angle. Home in on what works.
3
9
87
@raymondh
Raymond Hettinger
6 months
With the itertool module: • next(compress(iterable, repeat(False)), None) • next(dropwhile(id, iterable), None) • next(islice(iterable, sys.maxsize, None), None) • iterator = groupby(iterable, key=lambda x: None) next(iterator, None) next(iterator, None) (that's all)
1
0
11
@raymondh
Raymond Hettinger
6 months
With builtins: • set(map(type, zip(iterable))) • min(map(bool, zip(iterable))) With the collections module: • deque(iterable, maxlen=0) (more)
1
0
10
@raymondh
Raymond Hettinger
6 months
#Python amusement: There are many ways to write the consume() itertools recipe. def consume(iterable): for _ in iterable: pass (more)
3
2
41
@raymondh
Raymond Hettinger
6 months
#Python tip: The w in r"\w+" stands for "wrong". False negatives: can't you've Mary's cul-de-sac non-profit False positives: _____ 123 Actual word tokens may include apostrophes and hyphens and may exclude underscores or numbers.
1
1
15
@raymondh
Raymond Hettinger
6 months
For me, the Desmos Graphing Calculator sparks joy. Its API designers are true craftsmen (and women). The tool is approachable for kids, powerful enough for real world use, and completely devoid of cruft/nonsense. It takes discipline to make something this good.
0
2
32
@bindureddy
Bindu Reddy
6 months
Overall, AI Is Making Humans More Stupid AI makes 1% of us smarter and the remaining 99% stupider. The 1% are using AI to learn and do things, and know how to use it effectively. The remaining 99% blindly use AI to copy homework, write emails they don't read, try vibe coding,
84
35
312
@raymondh
Raymond Hettinger
6 months
#Python musing: From a practical point of view, "infinite" is just a special case of "inconveniently large". There is nothing special about: sum(itertools.count()) as compared to: sum(range(10**20))
0
2
22
@denicmarko
Marko Denic
6 months
This is 100% true!
51
590
10K
@mitsuhiko
Armin Ronacher ⇌
6 months
asyncio is still really wild in 2025. I haven't actively written asyncio code in a while but now that I have done it for a week agian, I noticed that most problems from when I used it last are still unresolved. Problem 1: asyncio.create_task is a massive footgun because it can
30
67
716
@raymondh
Raymond Hettinger
7 months
#Python tip: operator.itemgetter() accepts slice objects. >>> from operator import itemgetter >>> chomp_ends = itemgetter(slice(1, -1)) >>> chomp_ends('abcdefgh') 'bcdefg'
1
2
53