While writing custom modules, I've found the tp_members type entry very
useful. (As background, it is a pointer to a constant structure that
defines direct access sizes and types of member variables within your
custom PyObject ).
However, the defined type enumeration (including T_USHORT, T_UINT,
> def flatten(x):
> for i in range(len(x)):
> if isinstance(x[i], list):
> x[i:i+1] = x[i]
I don't think this does what you want. Try [[[1,2,3]]] as a trivial
example.
A recursive version, that's not as short as yours:
def flatten(x):
"Recursive example to flatten a
Or, (to add needed recursion to your simple loop):
def flatten(x):
"Modified in-place flattening"
for i in range(len(x)):
if isinstance(x[i], list):
x[i:i+1] = flatten(x[i])
return x
This version modifies in-place (as yours does), which may or may not be
what you w