The function below accepts one parameter: a string (date_string) containing a date in the mm/dd/yyyy format. Complete the function to return a list of integers representing the date components in month, day, year order. For example, given the string '06/11/1930', the code should return the list [6, 11, 1930].

Answered on

To complete the function as described, you would need to perform the following steps in your code:

1. Split the input string `date_string` using the '/' character as the delimiter. This will give you a list where each element is a string representing the month, day, and year.

2. Convert each element of the list from a string to an integer.

3. Return the new list of integers.

Here is a sample Python function that accomplishes this:

```python def parse_date(date_string): # Split the date_string into components date_components = date_string.split('/') # Convert each string component into an integer date_components = [int(component) for component in date_components] # Return the list of integers return date_components

# Example usage: date = '06/11/1930' print(parse_date(date)) # Output: [6, 11, 1930] ```

When you call `parse_date('06/11/1930')`, it would return `[6, 11, 1930]`.

Related Questions