Question

Define a Python function that takes a list and returns the length of the list using...

Define a Python function that takes a list and returns the length of the list using map and sum.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE IN PYTHON:

def length(inputList):
    count = sum(map(lambda x : x%1 == 0, inputList))
    return count

inputList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print("The list is : ", inputList)
print("The length of your list is : ", length(inputList))

INDENTATION:

def length(inputList): count = sum(map(lambda x : %1 == 0, inputList)) return count inputlist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1

OUTPUT:

numbersLength C:\Users\madhu\venv\Python3.8\Scripts\python.exe D:/PythonWorld/HelloWorld/numbersLength.py The list is : [1, 2

Add a comment
Know the answer?
Add Answer to:
Define a Python function that takes a list and returns the length of the list using...
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
  • Python Language:Define function that asks for a name and displays it.Define function that takes a name...

    Python Language:Define function that asks for a name and displays it.Define function that takes a name as a parameter and displays the nameDefine function "smallest" that returns the smallest number from a list given as parameterDefine function that takes length in feet and inches and returns meters.Implement queues using lists in Python. Define functions enqueue(list, element) and dequeue(list) that perform needed operations.

  • 1. Define a function in python that returns the sum of the following 4 lists. Remember...

    1. Define a function in python that returns the sum of the following 4 lists. Remember to store and re- use your code instead of summing the values for each list 4 times. Hence, define a function that takes as an argument a list and returns the sum of values. Copy the following lists and paste them in a Python file after you define the sum_of_values function Call the function and pass to it a different list each call as...

  • Python 2.7 Write a function cumsum() that takes a list l as argument and returns the...

    Python 2.7 Write a function cumsum() that takes a list l as argument and returns the cumulative sum (also known as the prefix sum) of l, which is a list, say cs of the same length as l such that each element cs[i] is equal to the sum of the first i + 1 elements of l, i.e., cs[i] == l[0] + l[1] + l[2] + ... + l[i] You should not modify the argument list l in any way....

  • 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

  • In python: FindWordCount is a function that takes in a list and a string. The function...

    In python: FindWordCount is a function that takes in a list and a string. The function then returns the number of occurances of the string in the list. Here's an example of using this function: >>> a = LoadFile("alice.txt") >>> PrintOutput(str(FindWordCount(a, "Alice"))) OUTPUT 403

  • Define a python function even(string) that accepts a python string of any length and returns a...

    Define a python function even(string) that accepts a python string of any length and returns a new string made of just the characters with even indexes For example even('Final exam') should return a string 'Fnlea'.

  • Using Python Programming Language: 3. Write a function flatten that takes a 2D list and returns...

    Using Python Programming Language: 3. Write a function flatten that takes a 2D list and returns all the items of each list concatenated together into one new 1D list. For example: flatten ([["a", "b"],["c","0"],["e","f"]]) would return ["a", "b","C","d", "e","f"] Save the function in a PyDev library module named functions.py Write a program t03.py that tests flatten function and prints the returned flat list to the screen. Test your program with a different list, hardcoded in t03.py • Copy the results...

  • Problem 1. Write a Python function times_i_at_odd(L) that takes as arguments a list L and returns...

    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],...

  • in python A. Define a function called contains_only_integers() that takes a tuple, returns True if all...

    in python A. Define a function called contains_only_integers() that takes a tuple, returns True if all the items in the tuple are integers(2), and returns False otherwise. For example, contains_only_integers (3, 5, 17, 257, 65537) ), contains_only_integers( (-1,) ), and contains_only_integers( ) should all return True, but contains_only_integers (2.0,4.0)) and contains_only_integers (8, 4, "2", 1)) should both return false. Your function should use a while loop to do this calculation. 121 Hint: the is instance() built-in function provides the most...

  • write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple

    1 write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple. Hint (can be done in one pass, you are not allowed to use built-on min and max functions.)max, min = find_max_min(my_list):2 write a Python function that takes in a list of integers (elements), and an integer number (num). The functions should count and return number of integers in elements greater than, less than, and equal to...

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