You can use this assignment in your class!
Mastery Progress(100.0%)
i

Collections in Python Assignment

You answeredJUST NOW
Python
You passed all test cases!
STDIN
1 1 2 3 4
Expected STDOUT
[2, 3, 4]
Your STDOUT
[2, 3, 4]
STDIN
1 1 2 2 3 3
Expected STDOUT
[]
Your STDOUT
[]
STDIN
1 2 2 3
Expected STDOUT
[1, 3]
Your STDOUT
[1, 3]
STDIN
22 55
Expected STDOUT
[22, 55]
Your STDOUT
[22, 55]
STDIN
1 2 3 4 5
Expected STDOUT
[1, 2, 3, 4, 5]
Your STDOUT
[1, 2, 3, 4, 5]
STDIN
1 5 3 5 2
Expected STDOUT
[1, 3, 2]
Your STDOUT
[1, 3, 2]

Did you like this question?

(Voting helps us personalize your learning experience!)
imgInstructor solution
Instructor Alec KretchJAN. 16, 2021 AT 8:33 PMstarTop Answer
Python

Was this helpful?

(Voting helps us personalize your learning experience!)
imgCollections in Python Presentation (pages 3, 4, 7, 8)

Was this helpful?

(Voting helps us personalize your learning experience!)
Think you've got it?
  • def remove_dups(a_list):
    counts = {} # Count how many times each value appears in a_list
    # Iterate a_list twice...
    # First time to count occurrences of each value
    for val in a_list:
        if val in counts:
            counts[val] += 1
        else:
            counts[val] = 1
    # Second time to build up our return list
    no_dups_list = []
    for val in a_list:
        if counts[val] < 2:
            no_dups_list.append(val)
    return no_dups_listFigure A
  • A.
  • B.
  • C.
  • D.
  • E.

Was this helpful?

(Voting helps us personalize your learning experience!)

You may exit out of this review and return later without penalty.