Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save syamdev/199858bd7eda991a02146fe4ddd995ed to your computer and use it in GitHub Desktop.
Save syamdev/199858bd7eda991a02146fe4ddd995ed to your computer and use it in GitHub Desktop.
Check Remove Duplicate Value From Another File
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Check Remove Duplicate Value From Another File",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyOCCApuzGTxCFiQMGDJ5Qjt",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/syamdev/199858bd7eda991a02146fe4ddd995ed/check-remove-duplicate-value-from-another-file.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "bPS2gRr6fW7T",
"outputId": "8ca3bf0f-14d3-420f-9e6c-470204b91359"
},
"source": [
"data = \"data.txt\"\n",
"source = \"source.txt\"\n",
"\n",
"def get_list_from_file(filename):\n",
" # filename: name of file\n",
" getlist = []\n",
" with open(filename, \"r\") as file:\n",
" for line in file:\n",
" getlist.append(line)\n",
"\n",
" return getlist\n",
"\n",
"source_list = get_list_from_file(source)\n",
"data_list = get_list_from_file(data)\n",
"\n",
"result = []\n",
"for i in data_list: \n",
" if i not in source_list: \n",
" result.append(i)\n",
" print(i.strip())"
],
"execution_count": 176,
"outputs": [
{
"output_type": "stream",
"text": [
"2221\n",
"4441\n",
"6661\n",
"8881\n",
"1234\n",
"5678\n",
"8987\n",
"3456\n",
"3343\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "NWiNh84XtKNI"
},
"source": [
""
],
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment