Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{
"cells": [
{
"cell_type": "code",
"execution_count": 656,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['“I do things like get in a taxi and say,\\n',\n",
" '\"The library, and step on it.”']"
]
},
"execution_count": 656,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import random\n",
"wallace = [line for line in open(\"wallace_text.txt\")]\n",
"\n",
"wallace"
]
},
{
"cell_type": "code",
"execution_count": 657,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"['Suppose that a person, call him Andrew. Andrew has a desire to drink a cup of tea.\\n',\n",
" 'He boils the kettle, pours the hot water into the teacup, places the teacup on a side table, and sits down next to it to wait for the tea to brew. When Andrew looks away, and before he is able to satisfy his desire, Beata quickly pours Andrew’s tea into a nearby plant pot because she believes that caffeine is bad for Andrew’s health.\\n',\n",
" 'Let us call this example ‘Tea Plant’.\\n',\n",
" '\\n',\n",
" 'Now imagine a different case.\\n',\n",
" 'Andrew has the desire to drink a cup of tea, and then, rather than pouring away the tea, Beata sprays a chemical in the air that stops Andrew drinking that cup of tea. as Andrew begins to lift the cup to his lips, the spray extinguishes his desire to drink the tea. Andrew knows that Beata’s spray was the cause of this change.\\n',\n",
" 'Let us call this example ‘Tea Spray’.']"
]
},
"execution_count": 657,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tea = [line for line in open(\"tea.txt\")]\n",
"\n",
"tea"
]
},
{
"cell_type": "code",
"execution_count": 849,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Tea Plant\n"
]
}
],
"source": [
"import random\n",
"from random import randint\n",
"\n",
"tea_example = [\"Tea Spray\" , \"Tea Plant\"]\n",
"\n",
"print(tea_example[randint(0,1)])"
]
},
{
"cell_type": "code",
"execution_count": 906,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"“I do things like get in a taxi and say, \"Tea Plant, and step on it.”\n",
"\n",
"The driver looks at me through the rear view mirror, and says:\n",
"\n",
"Suppose that a person, call him Andrew. Andrew has a desire to drink a cup of tea.\n",
"He boils the kettle, pours the hot water into the teacup, places the teacup on a side table, and sits down next to it to wait for the tea to brew. When Andrew looks away, and before he is able to satisfy his desire, Beata quickly pours Andrew’s tea into a nearby plant pot because she believes that caffeine is bad for Andrew’s health.\n",
"Let us call this example ‘Tea Plant’.\n",
"\n"
]
}
],
"source": [
"wallace_replace = [line.strip().replace(\"The library\" , tea_example[randint(0,1)]) for line in wallace]\n",
"\n",
"wallace_full = \" \".join(wallace_replace)\n",
"\n",
"print (wallace_full + \"\\n\" + \"\\nThe driver looks at me through the rear view mirror, and says:\" + \"\\n\") \n",
"\n",
"for x in wallace_replace:\n",
" if \"Plant\" in x:\n",
" print(tea[0] + tea[1] + tea[2])\n",
" elif \"Spray\" in x:\n",
" print(tea[0] + tea[5] + tea[6])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"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.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment