Assignment
# 1. Write a python function that returns the index of the smallest element in a list of
# integers. If the number of such elements is greater than 1, return the smallest index.
# Use the following function header:
# def indexOfSmallestElement(lst):
lst = [2,3,1,7,1,8]
def indexOfSmallestElement(lst):
smallest = lst.index(min(lst))
return smallest
indexOfSmallestElement(lst)
2
# 2. Write the python function mostCommonName, that takes a list of names (such as ["Ja
# ne", "Aaron", "Cindy", "Aaron"], and returns the most common name in this list
# (in this case, "Aaron"). If there is more than one such name, return a set of the most
# common names. So mostCommonName(["Jane", "Aaron", "Jane", "Cindy", "Aaron"])
# returns the set {"Aaron", "Jane"}. If the set is empty, return None. Also, treat names
# case sensitive, so "Jane" and "JANE" are different names.
lst = ["Jane", "Aaron", "Jane", "Cindy", "Aaron"]
def most_common(lst):
if max([lst.count(i)for i in lst]) == 1:
return False
else:
return max(set(lst), key=lst.count)
most_common(lst)
'Jane'
# 3. Write the python function isPalindromicList(a) that takes a list and returns True if it is
# the same forwards as backwards and False otherwise.
def isPalindrome(a):
return a == a[::-1]
a = "madam"
ans = isPalindrome(a)
if ans:
print("True")
else:
print("False")
True