Skip to content

Instantly share code, notes, and snippets.

@Snawoot
Created July 5, 2013 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Snawoot/5934408 to your computer and use it in GitHub Desktop.
Save Snawoot/5934408 to your computer and use it in GitHub Desktop.
def checkio(data):
#Your code here
#It's main function. Don't remove this function
#It's using for auto-testing and must return a result for check.
#replace this for solution
sorted_pairs = sorted(enumerate(data),None,lambda (index, element): element)
count = len(data)
if count == 1:
return []
nonuniq_sorted_pairs = map(lambda (prev, this, next): this, filter(lambda (prev, this, next): prev[1]==this[1] or next[1]==this[1], zip(sorted_pairs,sorted_pairs[1:],sorted_pairs[2:])))
if sorted_pairs[0][1]==sorted_pairs[1][1]:
nonuniq_sorted_pairs.append(sorted_pairs[0])
if sorted_pairs[count-2][1]==sorted_pairs[count-1][1]:
nonuniq_sorted_pairs.append(sorted_pairs[count-1])
return map(lambda (index, element): element, sorted(nonuniq_sorted_pairs,None,lambda (index, element): index))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment