Question

python 1. using filter to return even number 2.reverse list [1,2,[3,4,5],6] must return [6, [5,4,3],2,1]

python
1. using filter to return even number
2.reverse list [1,2,[3,4,5],6]
must return [6, [5,4,3],2,1]

Homework Answers

Answer #1

1.

CODE

lis1 = [10, 21, 30, 14, 5]

is_even = lambda x: x % 2 == 0

# using filter

lis2 = list(filter(is_even, lis1))

print(lis2)

2.

CODE

def is_list(p):

return isinstance(p, list)

def deepReverse(mylist):

result = []

for e in mylist:

if isinstance(e, list):

result.append(deepReverse(e))

else:

result.append(e)

result.reverse()

return result

print(deepReverse([1,2,[3,4,5],6]))

Know the answer?
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
Similar Questions
Write a Python function to count the number of even numbers from a list of numbers....
Write a Python function to count the number of even numbers from a list of numbers. Write a Python function that takes a list and returns a new list with unique elements of the first list. Sample List : [1,2,3,3,3,3,4,5] Unique List : [1, 2, 3, 4, 5]
Python Mutable Sequences Implement a function reverse that takes a list as an argument and reverses...
Python Mutable Sequences Implement a function reverse that takes a list as an argument and reverses the list. You should mutate the original list, without creating any new lists. Do NOT return anything. Do not use any built-in list functions such as reverse(). def reverse(lst):    """Reverses lst in place (i.e. doesn't create new lists).     >>> L = [1, 2, 3, 4]     >>> reverse(L)     >>> L     [4, 3, 2, 1]     """
Python, using recursion Given an list of ints, compute recursively the number of times that the...
Python, using recursion Given an list of ints, compute recursively the number of times that the value 11 appears in the list. We'll use the convention of considering only the part of the list that begins at the given index. In this way, a recursive call can pass index+1 to move down the array. The initial call will pass in index as 0. array11([1, 2, 11], 0) → 1 array11([11, 11], 0) → 2 array11([1, 2, 3, 4], 0) →...
2. Using a “for loop” print all even numbers in rage from 1 to 1000. Also,...
2. Using a “for loop” print all even numbers in rage from 1 to 1000. Also, please count and print how many even numbers you have found. 3. Using the following list and a “for” loop, display differences of all consecutive pairs of numbers in the list. our_list = [1,2,5,6,3,77,9,0,3,23,0.4,-12.4,-3.12] The output should look like this: 1 3 1 … 4. Using a “while loop” ask the user for a number and add it to a list if number is...
def count_evens(values: List[List[int]]) -> List[int]: """Return a list of counts of even numbers in each of...
def count_evens(values: List[List[int]]) -> List[int]: """Return a list of counts of even numbers in each of the inner lists of values.    >>> count_evens([[10, 20, 30]]) [3] >>> count_evens([[1, 2], [3], [4, 5, 6]]) [1, 0, 2] """   
def count_evens(values: List[List[int]]) -> List[int]: """Return a list of counts of even numbers in each of...
def count_evens(values: List[List[int]]) -> List[int]: """Return a list of counts of even numbers in each of the inner lists of values.    >>> count_evens([[10, 20, 30]]) [3] >>> count_evens([[1, 2], [3], [4, 5, 6]]) [1, 0, 2] """
python define prime number, return Ture False do not use loop or recursion using map() can...
python define prime number, return Ture False do not use loop or recursion using map() can using divides() def divides(n): def div(m): return n%k==0 return div code must be less than 4lines
Assignment 1. Console Application IN PYTHON For this assignment you are to create a class called...
Assignment 1. Console Application IN PYTHON For this assignment you are to create a class called Lab1. Inside the class you will create three methods that will modify a three-digit whole number: sumNums - This method takes as input a three digit int and returns the sum of the three numbers. For instance, 123 would return 6 because 3 + 2 + 1 is 6 reverseNums - This method takes as input a three digit whole number and returns the...
write code using python or repl.it 1. List 4 attributes that you'd create for class "student"....
write code using python or repl.it 1. List 4 attributes that you'd create for class "student". 2. List 2 setters and 2 getters for class student including their parameters 3. Write the complete definition for class student including attributes and methods created above using the correct Python syntax. 4. Create one object of class student and print the values of all its attributes. You can either call the getter method or access the attribute directly using the dot notation.
PYTHON------------ Task 1- Remove Number Complete the function remove_number such that given a list of integers...
PYTHON------------ Task 1- Remove Number Complete the function remove_number such that given a list of integers and an integer n, the function removes every instance of n from the list. Remember that this function needs to modify the list, not return a new list. Task 2- Logged List The log2() function is one of an algorithm designer’s favourite functions. You’ll learn more about this later, but briefly – if your input size is 1048576 elements, but you only look at...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT