Created
July 13, 2014 02:55
-
-
Save szeitlin/9c8db174398faf3b89d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'szeitlin' | |
def return_duplicates(nums): | |
""" | |
(list) -> (sub-list) | |
look for duplicates and just return those | |
>>> return_duplicates([5,5,2,3,4,5,2]) | |
[2, 2, 5, 5, 5] | |
>>> nums = [5,2,3,4,5,2] | |
>>> return_duplicates(nums) | |
[2, 2, 5, 5] | |
>>> nums = [5,5] | |
>>> return_duplicates(nums) | |
[5, 5] | |
""" | |
seen = [] | |
for i in range(len(nums)): | |
key = nums.pop() | |
if key in nums: | |
seen.append(key) | |
elif key not in nums: | |
if key in seen: | |
seen.append(key) | |
if len(nums) ==1: | |
if nums in seen: | |
seen.append(key) | |
seen.sort() | |
return seen | |
import doctest | |
doctest.testmod() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment