1. #!/usr/bin/python
  2.  
  3. """
  4. if shared folders not working, run this:
  5.  
  6. sudo adduser $USER vboxsf
  7.  
  8. then try again
  9.  
  10. =====================
  11.  
  12. goto
  13. http://askubuntu.com/questions/207813/why-does-an-ubuntu-12-10-guest-in-virtualbox-run-very-very-slowly
  14.  
  15. do this:
  16.  
  17.  
  18. # 1111111
  19. # run these command one at a time
  20. # (i.e. dont paste them in all at once)
  21.  
  22. cd /media/$USER/VBOX*
  23. sudo apt-get install linux-headers-$(uname -r) build-essential
  24. sudo ./VBoxLinuxAdditions.run
  25. sudo bash -c 'echo vboxvideo >> /etc/modules'
  26. sudo shutdown now
  27.  
  28. ## then in the VirtualBox control app
  29.  
  30. go to Settings>Display
  31. click on "Enable 3d acceleration"
  32.  
  33. # then reboot and thing should be faster
  34.  
  35. # also, so speed things up
  36.  
  37. sudo synaptic
  38. select lubuntu-desktop
  39. select lubuntu-restricted-extras
  40.  
  41. then log off and on the password screen, change the
  42. desktop manager to lubuntu (look for the white circle)
  43.  
  44. """
  45.  
  46. from go import *
  47. import sys
  48. def say(x):
  49. sys.stdout.write("["+x+"]")
  50.  
  51. @go
  52. def _string1(fruit="banana"):
  53. index = 0
  54. while index < len(fruit):
  55. letter = fruit[index]
  56. say(letter)
  57. index = index + 1
  58.  
  59. print xrange(1,10)
  60.  
  61. import string
  62. #@go
  63. def _string2():
  64. "finds 'na' at '2' (i.e. third arg)"
  65. print string.find("banana", "na")
  66.  
  67. #@go
  68. def _string3():
  69. "as above, but starts at 3"
  70. print string.find("banana", "na", 3)
  71.  
  72. #@go
  73. def _string4():
  74. "fails: specificed range has no 'na'"
  75. print string.find("banana", "na", 2,3)
  76.  
  77. #@go
  78. def _whites():
  79. print "[" + string.whitespace+"]"
  80. for ch in string.whitespace:
  81. print ord(ch),"["+ch+"]"
  82.  
  83.  
  84. #@go
  85. def _lowers():
  86. print string.lowercase
  87.  
  88. #@go
  89. def isLower1(ch="a"):
  90. print string.find(string.lowercase, ch) != -1
  91.  
  92. #@go
  93. def isLower2(ch="b"):
  94. print ch in string.lowercase
  95.  
  96. #@go
  97. def isLower3(ch="c",banner="hekko there"):
  98. print banner,'a' <= ch <= 'z'
  99.  
  100.  
  101. #@go
  102. def _test1():
  103. isLower3(banner="work more on python",ch="D")
  104.  
  105. #@go
  106. def _slice():
  107. a=[1,2,3,4]
  108. print 0,a[0]
  109. print 1,a[1:]
  110. print 2,a[:2]
  111. print 1,3,a[1:3]
  112. print -1,a[-1]
  113.  
  114. #@go
  115. def _alias():
  116. a = [1, 2, 3]
  117. b = a
  118. a[0]=100
  119. print a,b
  120.  
  121.  
  122. #@go
  123. def _clones():
  124. a = [1, 2, 3]
  125. b = a[:]
  126. a[0]=100
  127. print a,b
  128. @go
  129. def _dict():
  130. inventory = {'apples': 430,
  131. 'bananas': 312, 'oranges': 525,
  132. 'pears': 217}
  133. print "\n:all",inventory
  134. del inventory['pears']
  135. print "\n:less",inventory
  136. print "\n:keys",inventory.keys()
  137. print "\n:values",inventory.values()
  138. print "\n:parts",inventory.items()
  139. print "\n:iterate"
  140. for key,value in inventory.items():
  141. print ":key",key,":value",value
  142.  
  143. #@go
  144. def _counts():
  145. seen = {}
  146. for letter in "Mississippi":
  147. seen[letter] = seen.get(letter, 0) + 1
  148. print seen
  149.  
  150. import copy
  151.  
  152. class Holds(dict):
  153. """Dictionary with a default value for unknown keys."""
  154. def __init__(self, default):
  155. self.default = default
  156. def __getitem__(self, key):
  157. if key in self: return self.get(key)
  158. return self.setdefault(key, copy.deepcopy(self.default))
  159.  
  160. @go
  161. def _holds1():
  162. d = Holds(0)
  163. d['hello'] += 1
  164. print d
  165.  
  166. #@go
  167. def _holds2():
  168. d2 = Holds([])
  169. d2[1].append('hello')
  170. d2[2].append('world')
  171. d2[1].append('there')
  172. print d2
  173.  
  174. @go
  175. def _bigrams(words='i am what i am'.split()):
  176. "Counts of word pairs, in a dict of dicts."
  177. d = Holds(Holds(0))
  178. pairs=zip([None] + words, words + [None])
  179. for (w1, w2) in pairs:
  180. d[w1][w2] += 1
  181. print pairs
  182. print d
  183.  
  184. # d[w1][w2] += 1 looks better than
  185. # d.setdefault(w1,{}).setdefault(w2, 0); d[w1][w2] += 1