Question

def second_index(a_list, number): Accepts a list of integers and an integer, and returns the index of the SECOND occurrence o

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

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:

In [10]: def second_index(a_list, number): #list of all occurance 1st=[i for i, n in enumerate(a_list) if n == number ] if le

===========================================================================

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:

In [20]: def hasEveryLetter(s): for x in s: #check if the letter is Lower if x.islower(): #count the number of occurance of e

In [21]: def hasEveryLetter(s): for x in s: #check if the letter is Lower if x.islower(): #count the number of occurance of e

Add a comment
Know the answer?
Add Answer to:
def second_index(a_list, number): Accepts a list of integers and an integer, and returns the index of...
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
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
ADVERTISEMENT