Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started