#!/usr/bin/python """ if shared folders not working, run this: sudo adduser $USER vboxsf then try again ===================== goto http://askubuntu.com/questions/207813/why-does-an-ubuntu-12-10-guest-in-virtualbox-run-very-very-slowly do this: # 1111111 # run these command one at a time # (i.e. dont paste them in all at once) cd /media/$USER/VBOX* sudo apt-get install linux-headers-$(uname -r) build-essential sudo ./VBoxLinuxAdditions.run sudo bash -c 'echo vboxvideo >> /etc/modules' sudo shutdown now ## then in the VirtualBox control app go to Settings>Display click on "Enable 3d acceleration" # then reboot and thing should be faster # also, so speed things up sudo synaptic select lubuntu-desktop select lubuntu-restricted-extras then log off and on the password screen, change the desktop manager to lubuntu (look for the white circle) """ from go import * import sys def say(x): sys.stdout.write("["+x+"]") @go def _string1(fruit="banana"): index = 0 while index < len(fruit): letter = fruit[index] say(letter) index = index + 1 print xrange(1,10) import string #@go def _string2(): "finds 'na' at '2' (i.e. third arg)" print string.find("banana", "na") #@go def _string3(): "as above, but starts at 3" print string.find("banana", "na", 3) #@go def _string4(): "fails: specificed range has no 'na'" print string.find("banana", "na", 2,3) #@go def _whites(): print "[" + string.whitespace+"]" for ch in string.whitespace: print ord(ch),"["+ch+"]" #@go def _lowers(): print string.lowercase #@go def isLower1(ch="a"): print string.find(string.lowercase, ch) != -1 #@go def isLower2(ch="b"): print ch in string.lowercase #@go def isLower3(ch="c",banner="hekko there"): print banner,'a' <= ch <= 'z' #@go def _test1(): isLower3(banner="work more on python",ch="D") #@go def _slice(): a=[1,2,3,4] print 0,a[0] print 1,a[1:] print 2,a[:2] print 1,3,a[1:3] print -1,a[-1] #@go def _alias(): a = [1, 2, 3] b = a a[0]=100 print a,b #@go def _clones(): a = [1, 2, 3] b = a[:] a[0]=100 print a,b @go def _dict(): inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217} print "\n:all",inventory del inventory['pears'] print "\n:less",inventory print "\n:keys",inventory.keys() print "\n:values",inventory.values() print "\n:parts",inventory.items() print "\n:iterate" for key,value in inventory.items(): print ":key",key,":value",value #@go def _counts(): seen = {} for letter in "Mississippi": seen[letter] = seen.get(letter, 0) + 1 print seen import copy class Holds(dict): """Dictionary with a default value for unknown keys.""" def __init__(self, default): self.default = default def __getitem__(self, key): if key in self: return self.get(key) return self.setdefault(key, copy.deepcopy(self.default)) @go def _holds1(): d = Holds(0) d['hello'] += 1 print d #@go def _holds2(): d2 = Holds([]) d2[1].append('hello') d2[2].append('world') d2[1].append('there') print d2 @go def _bigrams(words='i am what i am'.split()): "Counts of word pairs, in a dict of dicts." d = Holds(Holds(0)) pairs=zip([None] + words, words + [None]) for (w1, w2) in pairs: d[w1][w2] += 1 print pairs print d # d[w1][w2] += 1 looks better than # d.setdefault(w1,{}).setdefault(w2, 0); d[w1][w2] += 1