Question: # QUESTION 1 def element _ uniqueness ( L ) : ' ' ' ( list ) - > bool Returns True if all the
# QUESTION
def elementuniquenessL:
listbool
Returns True if all the elements in the list are distinct,
in other words, if there is no element in the list that appears more than once.
Precondition: L is not empty
elementuniqueness
False
elementuniqueness
True
elementuniqueness
False
elementuniqueness
True
elementuniqueness
False
elementuniqueness
True
Lsort
last None
for x in L:
if last is not None and x last:
return False
last x
return True
# QUESTION
def oneuniqueatleastL:
listbool
Returns True if there exist at least one element in L that is unique,
in other words, that appears exactlly once in the list
Precondition: L is not empty
oneuniqueatleast
True
oneuniqueatleast
True
oneuniqueatleast
True
oneuniqueatleast
False
oneuniqueatleast
True
oneuniqueatleast
False
oneuniqueatleast
True
sortedlist sortedL
for i in rangelensortedlist:
if i or sortedlisti sortedlisti and i lensortedlist or sortedlisti sortedlisti :
return True
return False
# QUESTION
def alluniqueL:
listintlist
Return a list of elements of L that appear exactlly once in L
Precondition: L is not empty
allunique
allunique
allunique
allunique
allunique
allunique
sortedlist sortedL
uniqueelements
i
while i lensortedlist:
if i or sortedlisti sortedlisti and i lensortedlist or sortedlisti sortedlisti :
uniqueelements.appendsortedlisti
while i lensortedlist and sortedlisti sortedlisti :
i
i
return uniqueelements
# QUESTION again
def elementuniquenessvL:
# make now a nd solution to elementuniqueness
# by making a call to allunique
# QUESTION again
def oneuniqueatleastvL:
# make now a nd solution to oneuniqueatleastv
# by making a call to allunique
# QUESTION
def countuniqueL:
listintint
Return the number of unique elements of L
ie the number of elements that appear exactlly once in L
Precondition: L is not empty
countunique
countunique
countunique
countunique
countunique
countunique
# QUESTION
def duplicatesL:
listint
Returns True if the given list L has duplicates, in other,
if it has at least one element that appears two or more times.
Precondition: L is not empty
duplicates
True
duplicates
False
duplicates
True
duplicates
False
duplicates
True
duplicates
False
# QUESTION
def majorityL:
list
An element of a list is called "majority" if MORE THAN half of the elements of the list are equal to it
This function returns the majority element of L if such an element exsits, otherwise it returns None
majority
majorityS
majority
majority
majority
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
