Question

Using python3: - return the location of the first occurrence of value in list lst. Returns...

Using python3:

- return the location of the first occurrence of value in list lst. Returns -1 if value is not in lst.

FindVal(lst, value)

- return a count of occurrence of value in list lst.

Homework Answers

Answer #1
def FindVal(lst, value):
    index = -1
    # Looping through each index
    for i in range(len(lst)):
        # Checking value at index i is value
        if(lst[i] == value):
            # seeing i to index
            index = i
            break
    # Returning index value
    return index

# Testing
print(FindVal([4,2,1,3,5], 1))
print(FindVal([4,2,1,3,1,5], 1))
print(FindVal([4,2,3,5], 1))

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
Implement in python a function avg_val(lst), which returns the average value of the elements in list....
Implement in python a function avg_val(lst), which returns the average value of the elements in list. For example, given a list lst: [19, 2, 20, 1, 0, 18], the function should return 10. The name of the method should be avg_val and the method should take one parameter which is the list of values to test. Here is an example call to the function print(avg_val([19, 2, 20, 1, 0, 18]))
Write python code for the queue class buuilt with a linked list using: First- returns first...
Write python code for the queue class buuilt with a linked list using: First- returns first value in queue, PrintQ-returns whole queue as list, RemoveValue-removes specific value from queue, RemoveIndex-removes value from queue by index
Define a function in Scheme which takes a list of numbers and a scalar and returns...
Define a function in Scheme which takes a list of numbers and a scalar and returns the rest of the list after the first occurrence of the scalar that was passed. An empty list should be returned if the value doesn't exist. For example, (list-past-scalar '(5 2 8 3 1 9 2 3) 3) #returns (1 9 2 3) (list-past-scalar '(37 18 38 65 90) 100) #returns ()
Write an assembly procedure Find to return the index of the first occurrence of a character...
Write an assembly procedure Find to return the index of the first occurrence of a character ch in a string str. If ch is not found in str the return value should be -1. Input parameters: None. Preconditions: The base address of str is stored in ecx. str is ‘\0’ terminated. ch is strored in bl. Return value: The return value should be stored in eax. Run and test your procedure using the following driver program: .386 .model flat, stdcall...
Using the count function, create a function that returns only the unique elements in a list....
Using the count function, create a function that returns only the unique elements in a list. Now try to do the same thing using the set function instead of count. For example: f([1,2,2,3]) gives back [1,2,3].
In Haskell How to write a function that receives a list and returns a list of...
In Haskell How to write a function that receives a list and returns a list of tuples that contains the character and number of occurrence on the list. for example: "Hello" -> [ ('H',1), ('e',1), ('l',2),('l',2),('o',1) ]
Describe an algorithm that takes as input a list of n integers and finds the location...
Describe an algorithm that takes as input a list of n integers and finds the location of the first even integer or returns -1 if there is no even integer in the list. Here is the operation's header: procedure locationOfFirstEven(a1, a2, a3, ..., an : integers)
Implement the STL find routine that returns the iterator containing the first occurrence of x in...
Implement the STL find routine that returns the iterator containing the first occurrence of x in the range that begins at start and extends up to but not including end. If x is not found, end is returned. This is a nonclass (global function) with signature template <typename Iterator, typename Object> iterator find( Iterator start, Iterator end, const Object & x );
Create a function that returns a boolean value if all-elements are not odd or even. Using...
Create a function that returns a boolean value if all-elements are not odd or even. Using Dr. Racket and the How to Design a Function (HtDF ) recipe, create a function that will return the following check-expect: (check-expect (all-elements? even? (list 1 2 3) false) (check-expect (all-elements? even? (list 2 4 6) true) (check-expect (all-elements? odd? (list 1 3 5) true) Can you find an element in the list where the predicate fails (return false)?
C++ code Please: 1. Write a function to find the first occurrence of a given letter...
C++ code Please: 1. Write a function to find the first occurrence of a given letter in a string, return the index. If not found, return -1. (2’) Input example: str = "Hello World!" find(str, 'e') Input example: str = "a random string" find(str, '3') Output example: 1 Output example: -1
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT