Write the code to find the singletons within a list. A singleton is a value which only appears once. Print a message if there aren't any singletons in the list. Input: A list of lists: [[5, 7, 8, 7,...

1 answer below »

Write the code to find the singletons within a list. A singleton is a value which only appears once. Print a message if there aren't any singletons in the list.


Input:



  • A list of lists: [[5, 7, 8, 7, "a", "b", "a", 5], [6, 9, 0, 9, 6, 0]]


Output:



  • List [5, 7, 8, 7, "a", "b", "a", 5] has the following singletons

    • 8

    • b



  • List [6, 9, 0, 9, 6, 0] does not have any singletons




Partial credit will be granted. The rubric is:



  • Processed the lists correctly (20 points)

  • Processed the elements within the list correctly (20 pts)

  • Logic to identify a singleton (20 pts)

  • Logic to generate the outputs (20 pts)

  • Comments that describe the logic (20 pts)

Answered Same DaySep 16, 2021

Answer To: Write the code to find the singletons within a list. A singleton is a value which only appears once....

Arun Shankar answered on Sep 17 2021
149 Votes
def find_singletons(lst):
# Store a list that will hold the singletons
result = []
# Scan t
he list 'lst' left to right.
for i in range(len(lst)):
found = False
# Check if the ith element is present
for j in range(len(lst)):
if(lst[i] == lst[j]) and (i != j): # ith...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here