Main Content

Pass Python Function to Python map Function

This 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'});

Display the length of each word by applying the Python® len function to the function. To indicate that py.len is a function, use the MATLAB® function handle notation @.,days)

Python returns a map object. To display the contents, type:

ans = 
  Python list with values:

    [6, 7, 9, 8, 6]

External Websites