Skip to content

Instantly share code, notes, and snippets.

@thinkjson
Created May 2, 2015 18:42
Show Gist options
  • Select an option

  • Save thinkjson/2175a74ed2dbfb4c728b to your computer and use it in GitHub Desktop.

Select an option

Save thinkjson/2175a74ed2dbfb4c728b to your computer and use it in GitHub Desktop.
yet another programming lesson
>>> 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
[]
>>>
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