| CMSC 201 |
Lab 7: PracticeAssignmentFor this lab, you'll be writing a program that takes as an argument a list of integers, and returns a list so that every unique element in the original list is in it's own list. So for the input [1, 2, 3, 1, 1, 2] you would return [ [1, 1, 1], [2, 2], [3]]. The list [1, 2, 3] would return [[1], [2], [3]].
#Group list takes a single list as input, and returns a list where
#every element of the original list is in it's own list (in the order in
#which it first appeared).
def groupList():
#Your code goes here
def main():
#When you are ready to test your program, tests go here.
If you have trouble getting started, break the problem down. We know we need a single, empty list to populate by the end. So the first thing you do can be to create that list. We can call that result. Next, we're going to iterate over the original list (which means we'll need a loop). For each item in the original list, we need to add it to result. There are two possible cases: we need to add to a list already in result, or we need to make a new sublist inside result, and then add it to that. |