Skip to content

Instantly share code, notes, and snippets.

@dequis
Created February 26, 2018 05:26
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 dequis/f707452bcc001edcdf573e44f7cdc789 to your computer and use it in GitHub Desktop.
Save dequis/f707452bcc001edcdf573e44f7cdc789 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 44,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"names = ['steven pinker', 'peter singer']"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(('steven', 'peter'), ('pinker', 'singer'))"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"splitnames = [x.split() for x in names]\n",
"\n",
"firstnames, lastnames = zip(*splitnames)\n",
"firstnames, lastnames"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(('pteven', 'seter'), ('sinker', 'pinger'))"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spps = {'s': 'p', 'p': 's'}\n",
"\n",
"nplitsames = [[spps[y[0]] + y[1:] for y in x] for x in splitnames]\n",
"\n",
"nirstfames, nastlames = zip(*nplitsames)\n",
"nirstfames, nastlames"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"['steven pinker',\n",
" 'peter singer',\n",
" 'steven singer',\n",
" 'peter pinker',\n",
" 'pteven sinker',\n",
" 'seter pinger',\n",
" 'pteven pinger',\n",
" 'seter sinker',\n",
" 'steven sinker',\n",
" 'peter pinger',\n",
" 'steven pinger',\n",
" 'peter sinker',\n",
" 'pteven pinker',\n",
" 'seter singer',\n",
" 'pteven singer',\n",
" 'seter pinker']"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"[' '.join(x) for x in (\n",
" zip(firstnames, lastnames) +\n",
" zip(firstnames, lastnames[::-1]) +\n",
" zip(nirstfames, nastlames) +\n",
" zip(nirstfames, nastlames[::-1]) +\n",
" zip(firstnames, nastlames) +\n",
" zip(firstnames, nastlames[::-1]) +\n",
" zip(nirstfames, lastnames) +\n",
" zip(nirstfames, lastnames[::-1])\n",
")]"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'steven pinker. peter singer. steven singer. peter pinker. pteven sinker. seter pinger. pteven pinger. seter sinker. steven sinker. peter pinger. steven pinger. peter sinker. pteven pinker. seter singer. pteven singer. seter pinker'"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"'. '.join(_47)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.14"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment