how to refactor nested for loop into smaller for loop assume each of them independent?
Steve D'Aprano
steve+python at pearwood.info
Sat Oct 8 22:19:38 EDT 2016
On Sun, 9 Oct 2016 12:53 pm, Chris Angelico wrote:
>> They're caught by identity, though - "except 'type error'" fails to
>> catch TypeError, and vice versa.
>
> Fascinating! What about: except sys.intern('type error') ? Or does
> interning of strings not exist yet :)
>>> intern
Unhandled exception: undefined name: intern
Stack backtrace (innermost last):
File "<stdin>", line 1
>>> import sys
>>> sys.intern
Unhandled exception: undefined name: intern
Stack backtrace (innermost last):
File "<stdin>", line 1
There's no `is` operator, or id() function, so it's impossible to tell
whether small ints and strings are interned/cached except by reading the
source. No longs (let alone unified int/long).
The weirdest thing seems to be that {} exists (and is called a dictionary,
not dict) but there's no dict builder syntax:
>>> type({})
<type 'dictionary'>
>>> d = {'a': 1}
Parsing error: file <stdin>, line 1:
d = {'a': 1}
^
Unhandled exception: run-time error: syntax error
and keys have to be strings:
>>> d = {}
>>> d[1] = 2
Unhandled exception: type error: illegal argument type for built-in
operation
Stack backtrace (innermost last):
File "<stdin>", line 1
>>> d['1'] = 2
>>> print d
{'1': 2}
There are functions (def) but not lambda, but no `class` statement.
Primitive days indeed. And yet already usable.
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.
More information about the Python-list
mailing list