map
FunctionThis example shows how to display the length of each word in a list.
Create a list of days of the work week.
days = py.list({'Monday','Tuesday','Wednesday','Thursday','Friday'});
Apply the Python® len
function
to the py.map
function to display the length of
each word. Use the MATLAB® function handle notation, @
,
to indicate py.len
is a function.
py.map(@py.len,days)
ans = Python list with no properties. [6, 7, 9, 8, 6]
Python version 2.7 returns a list.
Python versions 3.x return a map
object.
To display the contents, type:
py.list(py.map(@py.len,days))
ans = Python list with no properties. [6, 7, 9, 8, 6]