Iterator slicing: Basic syntax
Take the cookiebox example from earlier. If one wanted to retrieve a few cookies from the box, one way to do that would be through iterator slicing. Take the following as an example:
cookiebox = iter(["chocolate chip", "oatmeal raisin", "sugar",
"shortbread", "gingerbread"])
subbox = cookiebox$[0:2]
$
operator is used with the square brackets to indicate that we want to slice the iterator, or cut a section out of it to use. Try printing both subbox and cookiebox out to see how this worked.
Show Solution: