[Python-checkins] python/dist/src/Lib/test test_deque.py,1.7,1.8

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Sat May 8 21:15:03 EDT 2004


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24983/Lib/test

Modified Files:
	test_deque.py 
Log Message:
Add more examples.

Index: test_deque.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_deque.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** test_deque.py	1 Mar 2004 23:16:21 -0000	1.7
--- test_deque.py	9 May 2004 01:15:01 -0000	1.8
***************
*** 475,478 ****
--- 475,529 ----
  deque(['c', 'b', 'a'])
  
+ 
+ 
+ 
+ >>> def delete_nth(d, n):
+ ...     "del d[n]"
+ ...     d.rotate(-n)
+ ...     d.popleft()
+ ...     d.rotate(n)
+ ...
+ >>> d = deque('abcdef')
+ >>> delete_nth(d, 2)   # remove the entry at d[2]
+ >>> d
+ deque(['a', 'b', 'd', 'e', 'f'])
+ 
+ 
+ 
+ >>> def roundrobin(*iterables):
+ ...     pending = deque(iter(i) for i in iterables)
+ ...     while pending:
+ ...         task = pending.popleft()
+ ...         try:
+ ...             yield task.next()
+ ...         except StopIteration:
+ ...             continue
+ ...         pending.append(task)
+ ...
+ 
+ >>> for value in roundrobin('abc', 'd', 'efgh'):
+ ...     print value
+ ...
+ a
+ d
+ e
+ b
+ f
+ c
+ g
+ h
+ 
+ 
+ >>> def maketree(iterable):
+ ...     d = deque(iterable)
+ ...     while len(d) > 1:
+ ...         pair = [d.popleft(), d.popleft()]
+ ...         d.append(pair)
+ ...     return list(d)
+ ...
+ >>> print maketree('abcdefgh')
+ [[[['a', 'b'], ['c', 'd']], [['e', 'f'], ['g', 'h']]]]
+ 
+ 
  """
  




More information about the Python-checkins mailing list