(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 ***"
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]]))

![[[500], [30, 25, 24], [0]] [[12, [25], 24], [0]] Process finished with exit code 0](http://img.homeworklib.com/questions/c7b3d0f0-0e67-11ec-9e04-19e9c7ba431f.png?x-oss-process=image/resize,w_560)
(Python)Implement the function deep_list, which takes in a list, and returns a new list which contains...
Write a recursive function bag_to_set that takes a list as a parameter and returns a new list in which the values that were in the old list appear only once in the new list (the order should be preserved). Sample data: Old list: [4, 5, 3, 4, 5, 2, 2, 4] New list: [4, 5, 3, 2] The function signature is: def bag_to_set(bag): """ ------------------------------------------------------- Copies elements of a bag to a set. Use: new_set = bag_to_set(bag) ------------------------------------------------------- Parameters: bag...
Python. Write a function that takes in a list and returns the first nonzero entry. def nonzero(lst): """ Returns the first nonzero element of a list >>> nonzero([1, 2, 3]) 1 >>> nonzero([0, 1, 2]) 1 >>> nonzero([0, 0, 0, 0, 0, 0, 5, 0, 6]) 5 """ "*** YOUR CODE HERE ***"
Implement a Python function called revd that takes a chain of characters and returns a new chain with the double of the elements but in reverse order. In the main program, ask the user to input the chain of characters, call the function and display the result Example : Please enter a chain of characters: abcd ddccbbaa NOTE: This is a repost. Please DO NOT use GLOBAL Variables
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
def zigzag(text): Implement a function that takes a string and returns a new string that is a zig-zag rearrangement of it like the one in the examples below. • Parameters: text is a string (no validation needed) • Examples: zigzag('12345678') → '18273645' zigzag('123456789') → '192837465' zigzag('abcdefgh') → 'ahbgcfde' zigzag('GeorgeMason') → 'GneoosragMe' Remember, do not call input() or print() You must have at least one loop in each function. You cannot import any module. You cannot call any Python function...
For my question, I need to write a function in Python 3 called middle that takes a list and returns a new list that contains all elements but the first and last elements. After the implement this function, I need to pass lists to test the functionality of the middle function Prototype: middle(list)
implement function 2 in python. name the source file as
h1.py. A test file h1_test.py is provided
below!
h1_test.py
import re
import math
import pytest
from h1 import (change, strip_quotes, scramble, say, triples, powers)
def test_change():
assert change(0) == (0, 0, 0, 0)
assert change(97) == (3, 2, 0, 2)
assert change(8) == (0, 0, 1, 3)
assert change(250) == (10, 0, 0, 0)
assert change(144) == (5, 1, 1, 4)
assert change(97) == (3, 2, 0, 2)
assert change(100000000000)...
Problem 1. Write a Python function times_i_at_odd(L) that takes as arguments a list L and returns a list consisting of the elements of L multiplied by the index number of the element at odd positions. (Use list comprehensions) >>> times_i_at_odd([1,2,3,4,5,6,7,8,9,10]) [2, 12, 30, 56, 90] Problem 2. Write a recursive function sum_cols(grid, n) that takes a list of lists of integers grid and integer n and returns the sum of column n in grid. For example, the call sum_cols([[1,2,3,4], [10,20,30,40],...
def zigzag(text): Implement a function that takes a string and returns a new string that is a zig-zag rearrangement of it like the one in the examples below. • Parameters: text is a string (no validation needed) • Examples: zigzag('12345678') → '18273645' zigzag('123456789') → '192837465' zigzag('abcdefgh') → 'ahbgcfde' zigzag('GeorgeMason') → 'GneoosragMe' in python
Write a function that takes a string as a parameter and returns a new string that is the reverse of the old string. Python from test import testEqual def reverse(s): return s testEqual(reverse("hello"),"olleh") testEqual(reverse("l"),"l") testEqual(reverse("follow"),"wollof") testEqual(reverse(""),"")