Question: PYTHON Write a function first_n that accepts a list l and an int n and returns a list containing the first n items of l.

PYTHON

Write a function first_n that accepts a list l and an int n and returns a list containing the first n items of l. Your code should work for any value of n > 0. In the event that n is greater than the length of l, the entire list l should be returned. When n is 0, the empty list [] would be returned.

In [ ]: # write your function in this cell

 
 

In [ ]: # test your function in this cell, adding any additional cells you require

l = [1,2,3]
n = 2
first_n(l, n)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!