Question

(Python)Implement the function deep_list, which takes in a list, and returns a new list which contains...

(Python)Implement the function deep_list, which takes in a list, and returns a new list which contains only elements of the original list that are also lists. Use a list comprehension.

def deep_list(seq): ""

"Returns a new list containing elements of the original list that are lists.

>>> seq = [49, 8, 2, 1, 102]

>>> deep_list(seq) []

>>> seq = [[500], [30, 25, 24], 8, [0]]

>>> deep_list(seq) [[500], [30, 25, 24], [0]]

>>> seq = ["hello", [12, [25], 24], 8, [0]]

>>> deep_list(seq) [[12, [25], 24], [0]] """ "

*** YOUR CODE HERE ***"

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def deep_list(seq):
    return [x for x in seq if type(x)==list]

# Testing
print(deep_list([49, 8, 2, 1, 102]))
print(deep_list([[500], [30, 25, 24], 8, [0]]))
print(deep_list(["hello", [12, [25], 24], 8, [0]]))

Output:

[[500], [30, 25, 24], [0]] [[12, [25], 24], [0]] Process finished with exit code 0

Add a comment
Know the answer?
Add Answer to:
(Python)Implement the function deep_list, which takes in a list, and returns a new list which contains...
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