
Madhan Mohan Reddy Paidimarla
6,936 Pointscreate a function named first_4 that returns the first four items from whatever iterable is given to it.
create a function named first_4 that returns the first four items from whatever iterable is given to it.
first_4 = 1,2,3,4
1 Answer

James Arnold
3,972 PointsFirst thing, it's asking us to create a function instead of a just a variable like what we have here. To create a function we'll use:
def first_4(ctx):
return
So now that we have our function defined and we're passing in our value - ctx. We need to define the function to slice off the first four elements. This can be done using list slicing like so:
def first_4(ctx):
return ctx[:4]
Tlotlo Molokwe
16,594 PointsTlotlo Molokwe
16,594 Pointstry def first_4(num): return num[0:4]