Python Python Collections Slices Slice Functions

Artur Owczarek
Artur Owczarek
905 Points

Beginning Python - first_4 function

"Create a function named first_4 that returns the first four items from whatever iterable is given to it." Why I got error?

slices.py
def first_4(iterable)
    return iterable[:4]

3 Answers

bot .net
bot .net
10,084 Points

the answer is : def first_4(iterable): return iterable[0::4]

Martin Pearce
Martin Pearce
12,919 Points

I think you need to assign 'iterable' as a variable. also need a ':' in there somewhere too.

Artur Owczarek
Artur Owczarek
905 Points

Ahhh I didn't put colon in first line. :D Thanks for help.