cf.flat

cf.flat(x)[source]

Return an iterator over an arbitrarily nested sequence.

Parameters :
x : scalar or arbitrarily nested sequence

The arbitrarily nested sequence to be flattened. Note that a If x is a scalar then this is equivalent to passing a single element sequence containing the scalar.

Returns :
out : generator

An iterator over flattened sequence.

Examples

>>> for a in cf.flat([1, [2, [3, 4]]]):
...     print a,
1 2 3 4
>>> for a in cf.flat(['a', ['bc', ['def', 'ghij']]]):
...     print a, ' ',
a bc def ghij
>>> for a in cf.flat(2004):
...     print a
2004
>>> for a in cf.flat('abcdefghij'):
...     print a,
abcdefghij
>>> f
<CF Field: eastward_wind(air_pressure(5), latitude(110), longitude(106)) m s-1>
>>> for a in cf.flat(f):
...     print a
<CF Field: eastward_wind(air_pressure(5), latitude(110), longitude(106)) m s-1>
>>> for a in cf.flat([f, [f, [f, f]]]):
...     print a
<CF Field: eastward_wind(air_pressure(5), latitude(110), longitude(106)) m s-1>
<CF Field: eastward_wind(air_pressure(5), latitude(110), longitude(106)) m s-1>
<CF Field: eastward_wind(air_pressure(5), latitude(110), longitude(106)) m s-1>
<CF Field: eastward_wind(air_pressure(5), latitude(110), longitude(106)) m s-1>
>>> fl = cf.FieldList(cf.flat([f, [f, [f, f]]])
>>> fl
[<CF Field: eastward_wind(air_pressure(5), latitude(110), longitude(106)) m s-1>,
 <CF Field: eastward_wind(air_pressure(5), latitude(110), longitude(106)) m s-1>,
 <CF Field: eastward_wind(air_pressure(5), latitude(110), longitude(106)) m s-1>,
 <CF Field: eastward_wind(air_pressure(5), latitude(110), longitude(106)) m s-1>]

Previous topic

cf.dirname

Next topic

cf.pathjoin

This Page