Question

Python Write a function list_copy(l) that takes a list as a parameter and returns a copy...

Python Write a function list_copy(l) that takes a list as a parameter and returns a copy of the list using a list comprehension.

please provide unittest

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def list_copy(lst):
    return [x for x in lst]


lst1 = [3, 4, 1, 9]
lst2 = list_copy(lst1)
print(lst1)
print(lst2)
# now proving that they are not same object and they are different objects
lst1.append(2)
print(lst1)
print(lst2)

Add a comment
Know the answer?
Add Answer to:
Python Write a function list_copy(l) that takes a list as a parameter and returns a copy...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT