Code with explanation:
def second_index(a_list,number):
#list of all occurance
lst=[i for i, n in enumerate(a_list) if n == number ]
if len(lst)>1:
return lst[1]
else:
return None
print(second_index([2,34,3,45,34,45,3,3],3))
print(second_index([2,34,3,45,34,45,3,3],45))
print(second_index([2,34,3,45,134,45,3,3],134))
print(second_index([2,34,3,45,134,45,3,3],100))
===============================================
screenshot of output with code:
===========================================================================
Code with explanation:
def hasEveryLetter(s):
for x in s:
#check if the letter is lower
if x.islower():
#count the number of occurance of each letter
#in given string
cnt=[i for i, n in enumerate(s) if n == x]
#if occurance is greater than 1
#return False
if(len(cnt)>1):
return False
return True
print(hasEveryLetter("Apple"))
print(hasEveryLetter("aPPle"))
print(hasEveryLetter("bankruptcy"))
print(hasEveryLetter("Demography"))
===========================================
screenshot of output with code:
def second_index(a_list, number): Accepts a list of integers and an integer, and returns the index of...
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 --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...
Python code that Returns True if every letter of the (lowercase) alphabet can be found (at least once) in s, False otherwise
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.
1. Write a function called ordinal_sum that accepts a string argument and returns the sum of the ordinal values of each character in the string. The ordinal value of a character is its numeric Unicode code point in decimal. 2. Write code that creates a Python set containing each unique character in a string named my_string. For example, if the string is 'hello', the set would be {'h', 'e', 'l', 'o'} (in any order). Assign the set to a variable...
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,
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
What would be the output of the following code? def get_letter_index(letter, string): returns the index of letter in string, OR if letter is not found in string, prints that information instead. If the letter occurs multiple times, this returns only the first index where the letter is found. Index where the letter is found for i in range(len(string)): if string[i] == letter: return i #if execution reaches this point, we must not have found the letter print(letter, "not found in",...
Please help me with this python3 assignment. Write an iterative function, count_consonants(), that accepts a string (that can include upper and lowercase characters) and returns the number of consonants in that string. A consonant is defined as any letter in the English alphabet other than the vowels a, e, i, o, u. For example, if you call the function as follows: count_consonants('correct horse battery staple') the function should return 20.
In Python class int Set (object): "" "An intSet is a set of integers The value is represented by a list of ints, self.vals. Each int in the set occurs in self.vals exactly once. """ definit__(self): """Create an empty set of integers""" self.vals = 0 def insert (self, e): """Assumes e is an integer and inserts e into self""" if not e in self.vals: self.vals.append(e) def member (self, e): """Assumes e is an integer Returns True if e is in...