Skip to content

Instantly share code, notes, and snippets.

Created August 30, 2017 00:47
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 anonymous/5c2339e6ccab249788d24ffee7cbe9a6 to your computer and use it in GitHub Desktop.
Save anonymous/5c2339e6ccab249788d24ffee7cbe9a6 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{ "cells": [ { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1, George Washington, 1984, 1345\r\n", "2, John Adams, 1234, 4321,\r\n", "3, Thomas Jefferson, 1022, 1230 \r\n", "300, Thomas Jefferson, 1022, 1230 \r\n", "40, Franklin D. Roosevelt, 1022, 1230 \r\n", " 30, Thomas Jefferson, 1022, 1230 \r\n" ] } ], "source": [ "!cat input.txt" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1, Washington George,\n", "2, Adams John,\n", "3, Jefferson Thomas,\n", "300, Jefferson Thomas,\n", "40, Roosevelt D. Franklin,\n", "30, Jefferson Thomas,\n" ] } ], "source": [ "#!/usr/bin/env python3\n", "import csv\n", "\n", "with open('input.txt') as _f:\n", " reader = csv.reader(_f)\n", " for row in reader:\n", " reversed_names = reversed(row[1].split())\n", " reversed_names = ' '.join(reversed_names)\n", " msg = '{id}, {rev_names},'.format(\n", " id=row[0].strip(),\n", " rev_names=reversed_names,\n", " )\n", " print(msg)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 2}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment