Skip to content

Instantly share code, notes, and snippets.

@gdsaxton
Last active March 15, 2018 18:05
Show Gist options
  • Save gdsaxton/e5b6788421eb67cfc9ea6c8cb77d82b6 to your computer and use it in GitHub Desktop.
Save gdsaxton/e5b6788421eb67cfc9ea6c8cb77d82b6 to your computer and use it in GitHub Desktop.
Find Duplicates in List
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['twitter']"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import collections\n",
"mylist = ['twitter', 'facebook', 'instagram', 'twitter']\n",
"[item for item, count in collections.Counter(mylist).items() if count > 1]"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [default]",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment