Python code that:
Accepts a list of integers and an integer, and returns the index of
the SECOND occurrence of the integer in the list. It
returns None if the number does not occur two or more times in the
list.
Example 1: second_index([2,34,3,45,34,45,3,3], 3) returns 6
Example 2: second_index([2,34,3,45,34,45,3,3], 45) returns 5
Example 3: second_index([2,34,3,45,134,45,3,3], 134) returns
None
Example 4: second_index([2,34,3,45,134,45,3,3], 100) returns
None
PYTHON
# by default function retuns the none
def second_index(lst , n):
c = 0
#runs the loop
for i in range(len(lst)):
# checks the condition for integer
if(lst[i] == n):
# when integer finds out in the list c is increment
c+=1
#checks the
if(c==2):
# when integer finds for 2nd time then return then index of
return i
#calling a fucntion & passing the parameters & returned
value is stored into res variable
res = second_index([2,34,3,45,34,45,3,3],3)
#printing the returned value of function
print(res)
THANK YOU
THUMBS UP
Python code that: Accepts a list of integers and an integer, and returns the index of...
def second_index(a_list, number): Accepts a list of integers and an integer, and returns the index of the SECOND occurrence of the integer in the list. It returns None if the number does not occur two or more times in the list. Example 1: second_index ([2,34,3,45,34,45,3,3), 3) returns 6 Example 2: second_index( [2,34,3,45,34,45,3,3), 45) returns 5 Example 3: second_index ( [2,34,3,45,134,45,3,3), 134) returns None Example 4: second_index( [2,34,3,45, 134,45,3,3), 100) returns None return None def hasEveryLetter(s): #s is a string Returns...
PYTHON --create a function that accepts a list of numbers and an int that returns index of 2nd occurrence of the int in list, otherwise returns None if # does not repeat more 2 or more times EX: [10,24,3,45,10,49,4,5], 10) returns 4 --create a function that accepts a string that returns true if every letter of the alphabet can be found at least one time in the string, (has to be the lowercase alphabet), and false otherwise. for...
Write a method maxOccurrences that accepts a list of integers as a parameter and returns the number of times the most frequently occurring integer (the “mode”) occurs in the list. Solve this problem using a map as auxiliary storage. If the list is empty, return 0.
nonPrime_lst(L) accepts a list L of integers ( >1 ) and returns a list that contains all the Nonprime numbers picked from L. For example, nonPrime_lst([2,4,5,7,10,11,12,15,19] should return [4,10,12,15]). in Python
PYTHON CODE In a program, write a function that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all of the numbers in the list that are greater than the number n. Output should look like: Number: 5 List of numbers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] List of numbers that are larger than 5: [6, 7, 8, 9, 10]
Function name: triangular Parameters: integer Returns: a list Description: Write a function called triangular that accepts one integer parameter that returns a list with the same number of terms as the value of the parameter. If the parameter is zero or a negative number, you should return an empty list A triangular number is the sum of a positive integer and all the integers before it. The series is as follows: 1, 3, 6, 10, 15, 21,
In PYTHON: Write a function that receives a list of integers and returns the number of integers that are larger than the element immediately before them. For example, given [1,2,3,-5,0,-5,-10] the function should return 3 (since 1<2, 2<3, and -5<0).
Python Function Name: sign_count Parameters: a list of integers Returns: an integer Description: Speed signs should be posted every mile on a given street. You are given a list of 0s & 1s, where each number represents a quarter of a mile. Thus, every 4 zeroes requires a speed sign. However, a 1 indicates an intersection, and each intersection is automatically required to have a speed limit sign. A sign for each mile proceeds as usual after the intersection. Your...
python 3.7 write a function called read_file() which accepts a filename and returns a list of tuple objects. For example, if we have the following data: 0.000000000 192.168.0.24 10.0.0.5 H-NM 1.001451000 192.168.0.24 10.0.0.5 2.002970000 192.168.0.24 10.0.0.5 3.003552000 192.168.0.24 10.0.0.5 4.005007000 192.168.0.24 10.0.0.5 then the list should contain the following: [('192.168.0.24', 0, 84), ('192.168.0.24', 1, 84), ('192.168.0.24', 2, 84), ('192.168.0.24', 3, 84), ('192.168.0.24', 4, 84)] Note: • Each line consists of a number of fields separated by a single tab character....
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...