Created
May 2, 2015 18:42
-
-
Save thinkjson/2175a74ed2dbfb4c728b to your computer and use it in GitHub Desktop.
yet another programming lesson
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> from speech import say | |
| >>> words = [] | |
| >>> words | |
| [] | |
| >>> words.append("hello") | |
| >>> words | |
| ['hello'] | |
| >>> words.append("elisheva") | |
| >>> say(words) | |
| >>> words.reverse() | |
| >>> words | |
| ['elisheva', 'hello'] | |
| >>> say(words) | |
| >>> words.reverse() | |
| >>> words | |
| ['hello', 'elisheva'] | |
| >>> say(words) | |
| >>> words.append('says') | |
| >>> say(words) | |
| >>> words.append('daddy') | |
| >>> say(words) | |
| >>> words.append('when he gets home from work') | |
| >>> say(words) | |
| >>> words | |
| ['hello', 'elisheva', 'says', 'daddy', 'when he gets home from work'] | |
| >>> words.reverse() | |
| >>> say(words) | |
| >>> words.shuffle() | |
| Traceback (most recent call last): | |
| File "<stdin>", line 1, in <module> | |
| AttributeError: 'list' object has no attribute 'shuffle' | |
| >>> import random | |
| >>> random.shuffle(words) | |
| >>> words | |
| ['when he gets home from work', 'says', 'daddy', 'elisheva', 'hello'] | |
| >>> say(words) | |
| >>> words2 | |
| Traceback (most recent call last): | |
| File "<stdin>", line 1, in <module> | |
| NameError: name 'words2' is not defined | |
| >>> words2 = [] | |
| >>> words2.append(words.pop()) | |
| >>> words | |
| ['when he gets home from work', 'says', 'daddy', 'elisheva'] | |
| >>> words2 | |
| ['hello'] | |
| >>> words2.append(words.pop()) | |
| >>> words | |
| ['when he gets home from work', 'says', 'daddy'] | |
| >>> words2 | |
| ['hello', 'elisheva'] | |
| >>> daddy = words.pop() | |
| >>> daddy | |
| 'daddy' | |
| >>> words | |
| ['when he gets home from work', 'says'] | |
| >>> words2.append(words.pop()) | |
| >>> words | |
| ['when he gets home from work'] | |
| >>> words2 | |
| ['hello', 'elisheva', 'says'] | |
| >>> words2.append(daddy) | |
| >>> words | |
| ['when he gets home from work'] | |
| >>> words2 | |
| ['hello', 'elisheva', 'says', 'daddy'] | |
| >>> words2.append(words.pop()) | |
| >>> words2 | |
| ['hello', 'elisheva', 'says', 'daddy', 'when he gets home from work'] | |
| >>> say(words2) | |
| >>> say(words) | |
| >>> words | |
| [] | |
| >>> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import subprocess | |
| import shlex | |
| def say(text): | |
| text.insert('say', 0) | |
| subprocess.call() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment