Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> L = ['grail']
- >>> L.append(L)
- >>> L
- ['grail', [...]]
- >>> L[0]
- 'grail'
- >>> L[1][0]
- 'grail'
- >>> L[1][1][0]
- 'grail'
- V=["Boulder", "Denver", "Colorado Springs", "Pueblo", "Limon"]
- E=[["Boulder", "Denver"],
- ["Denver", "Colorado Springs"],
- ["Colorado Springs", "Pueblo"],
- ["Denver", "Limon"],
- ["Colorado Springs", "Limon"]]
- public class Direction
- {
- ...
- public IEnumerable<Direction> WithTwoNeighbors
- {
- get {
- yield return this;
- yield return this.CounterClockwise;
- yield return this.Clockwise;
- }
- }
- }
- ...
- public void TryToMove (Direction dir)
- {
- dir = dir.WithTwoNeighbors.Where (d => CanMove (d)).First ()
- Move (dir);
- }
- v[end] = a;
- end = (end+1) % N;
- if (begin == end)
- begin = (begin+1) % N;
- for (i=begin; i != end; i = (i+1) % N) {
- // do stuff
- }
- chicago[0] == denver
- chicago[0][0] == phoenix
- chicago[0][0][0] == chicago
- >>> L = ['foo', 'bar']
- >>> L.append(L)
- >>> L
- ['foo', 'bar', [...]]
- >>> L[0]
- 'foo'
- >>> L[1]
- 'bar'
- >>> L[2]
- ['foo', 'bar', [...]]
- >>> L[2].append('baz')
- >>> L
- ['foo', 'bar', [...], 'baz']
- >>> L[2]
- ['foo', 'bar', [...], 'baz']
- >>> L[2].pop()
- 'baz'
- >>> L
- ['foo', 'bar', [...]]
- >>> L[2]
- ['foo', 'bar', [...]]
- options,start_menu,about = [],[],[]
- def do_nothing(): pass
- about += [
- {'name':"copyright by...",'action':None,'menu':about},
- {'name':"back",'action':do_nothing,'menu':start_menu}
- ]
- options += [
- {'name':"volume up",'action':volumeUp,'menu':options},
- {'name':"save",'action':save,'menu':start_menu},
- {'name':"back without save",'action':do_nothing,'menu':start_menu}
- ]
- start_menu += [
- {'name':"Exit",'action':f,'menu':None}, # no next menu since we quite
- {'name':"Options",'action':do_nothing,'menu':options},
- {'name':"About",'action':do_nothing,'menu':about}
- ]
- >>> print about
- [{'action': None, 'menu': [...], 'name': 'copyright by...'},#etc.
- # see the ellipsis (...)
- def menu_item_pressed(item):
- log("menu item '%s' pressed" % item['name'])
- item['action']()
- set_next_menu(item['menu'])
- class SelfReferenceMarkerClass: pass
- #singleton global marker for self reference
- SelfReferenceMarker = SelfReferenceMarkerClass()
- about += [
- {'name':"copyright by...",'action':None,'menu':srm},
- {'name':"back",'action':do_nothing,'menu':start_menu}
- ]
- def menu_item_pressed(item):
- item['action']()
- if (item['menu'] == SelfReferenceMarker):
- set_next_menu(get_previous_menu())
- else:
- set_next_menu(item['menu'])
- class Client(object):
- def set_remote(self, remote_client):
- self.remote_client = remote_client
- def send(self, msg):
- self.remote_client.receive(msg)
- def receive(self, msg):
- print msg
- Jill = Client()
- Bob = Client()
- Bob.set_remote(Jill)
- Jill.set_remote(Bob)
- Bob.send("Hi, Jill!")
- Jill.send("Hi, Bob!")
Add Comment
Please, Sign In to add comment