I quite like the chirurgical, strategic feel of the exposition. Denotes clear thinking, and/or multiple revisions.
When I work in some code I often spend too much time on reviewing and enhancing code in this way, but mine being a side project all that work (I’m not the best programmer by far) is either for future me or for no one, and often I end up feeling that I lost time for nothing.
But I like to spend time in making this kind of clean code {shrug}.
I've read a lot of code. Peter Norvig's code operates at a different level to anything else I've ever read.
And he's been doing this a long time. I've read part of the way through "Paradigms of Artificial Intelligence Programming" which is from 1991, and uses much the same approach as in the OP, but with Common Lisp.
That kind of dramatic change usually only benefits people with nothing to lose or a distinct next-level gain to make.
Norvig definitely isn't in the first category and has many better avenues for gains than an attempted split of the US (think about who does potentially benefit from that).
Plus hackers love puzzles.
So it's not surprising that politics isn't what it was about.
when you pipe a set it's the same thing as calling union on each one, it creates a new set and puts all the variables in them:
so this:
border = north | south | west | east
is the same thing as:
border = north.union(south, west, east)
which is also:
border = set()
for border_set in [north, south, west, east]:
for state in border_set:
border.add(state)
it's just a new set with all the previous items in it. Since it's a set there is no doubles. for example, WA is in north and east, but only in border once, because there is no duplicates in a set.
to do it with lists you would need to make sure there was no doubles yourself. plus you wouldn't get the set operations later on, and would need similar loops to check things.
border = []
for state in north + south + west + east:
if state not in border:
border.append(state)
Sets are great any time you need to work with groups of unique things and see how they relate to each other. Since there is only one of each state, this is perfect use for them.
If sets were a Python-only thing I'd say that it's too clever, but it's a concept that appears in many other environments: Typescript (unions), Datalog and other declarative logic languages, Haskell (I think) and other functional languages...
So python is implementing an existing paradigm, not trying to be clever inventing something new. I'm happy with that
The image cannot be dispalied. I wish github only allowed Open Image Formats, but too late now since Microsoft owns them.
Lately I have been running into image/video files people at work create on their MACs that cannot be viewed in Linux. I wonder if that crap is carrying ofer into github.
[+] [-] harperlee|4 years ago|reply
When I work in some code I often spend too much time on reviewing and enhancing code in this way, but mine being a side project all that work (I’m not the best programmer by far) is either for future me or for no one, and often I end up feeling that I lost time for nothing.
But I like to spend time in making this kind of clean code {shrug}.
[+] [-] adolph|4 years ago|reply
[+] [-] biorach|4 years ago|reply
And he's been doing this a long time. I've read part of the way through "Paradigms of Artificial Intelligence Programming" which is from 1991, and uses much the same approach as in the OP, but with Common Lisp.
[+] [-] nl|4 years ago|reply
Obviously his approach is the right way. Except they usually aren't obvious until you've read the explanation.
His 22 line spell checker[1] is a perfect example.
[1] https://norvig.com/spell-correct.html
[+] [-] d_burfoot|4 years ago|reply
[+] [-] wwweston|4 years ago|reply
Norvig definitely isn't in the first category and has many better avenues for gains than an attempted split of the US (think about who does potentially benefit from that).
Plus hackers love puzzles.
So it's not surprising that politics isn't what it was about.
[+] [-] karolsputo|4 years ago|reply
[+] [-] wodenokoto|4 years ago|reply
Sets in Python are really cool when you can master them, but I do sometimes wonder if they are too clever, or just not evangelized enough.
[+] [-] dec0dedab0de|4 years ago|reply
so this:
is the same thing as: which is also: it's just a new set with all the previous items in it. Since it's a set there is no doubles. for example, WA is in north and east, but only in border once, because there is no duplicates in a set.to do it with lists you would need to make sure there was no doubles yourself. plus you wouldn't get the set operations later on, and would need similar loops to check things.
Sets are great any time you need to work with groups of unique things and see how they relate to each other. Since there is only one of each state, this is perfect use for them.edits throughout as I thought of other things.
[+] [-] williamdclt|4 years ago|reply
So python is implementing an existing paradigm, not trying to be clever inventing something new. I'm happy with that
[+] [-] unknown|4 years ago|reply
[deleted]
[+] [-] onychomys|4 years ago|reply
[+] [-] anonymous_they|4 years ago|reply
Maybe GitHub's rendering of ipynb files?
[+] [-] unknown|4 years ago|reply
[deleted]
[+] [-] archi42|4 years ago|reply
[+] [-] charleskinbote|4 years ago|reply
[+] [-] unknown|4 years ago|reply
[deleted]
[+] [-] serverlessmom|4 years ago|reply
[+] [-] jayspell|4 years ago|reply
[+] [-] hirundo|4 years ago|reply
"Welcome to The Riddler. Every week, I offer up problems related to the things we hold dear around here: math, logic and probability."
[+] [-] jmclnx|4 years ago|reply
Lately I have been running into image/video files people at work create on their MACs that cannot be viewed in Linux. I wonder if that crap is carrying ofer into github.
[+] [-] enobrev|4 years ago|reply
https://github.com/norvig/pytudes/raw/5e745c392772d150b41462...
Here's map4.png: https://github.com/norvig/pytudes/blob/main/ipynb/map4.png
There doesn't seem to be a 5 or 6.