Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> >>> gen_str(10) 'oqmfpojlmr' >>> L = gen_str(10**7) #too much time! Traceback (most recent call last): File "", line 1, in L = gen_str(10**7) File "C:\Documents and Settings\eladlibm\Desktop\hash.py", line 36, in gen_str s += random.choice(alphabet) File "C:\Python32\lib\random.py", line 250, in choice i = self._randbelow(len(seq)) File "C:\Python32\lib\random.py", line 226, in _randbelow r = getrandbits(k) # 0 <= r < 2**k KeyboardInterrupt >>> L = gen_str(10**6) #OK >>> L[:10] 'zmkorhfukz' >>> repeat_naive(L, 100) #too much time for the naive solution Traceback (most recent call last): File "", line 1, in repeat_naive(L, 100) File "C:\Documents and Settings\eladlibm\Desktop\hash.py", line 8, in repeat_naive if st[i:i+l]==st[j:j+l]: KeyboardInterrupt >>> repeat_hash2(L, 100) #fast False >>> repeat_hash1(L, 100) #a bit slower False Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> >>> L = [1,5,7,2] >>> iL = iter(L) >>> type(iL) >>> next(iL) 1 >>> next(iL) 5 >>> next(iL) 7 >>> next(iL) 2 >>> next(iL) Traceback (most recent call last): File "", line 1, in next(iL) StopIteration >>> iL2 = iter(L) >>> next(iL2) 1 >>> iL = iter(L) >>> next(iL2) 5 >>> next(iL2) 7 >>> next(iL3) Traceback (most recent call last): File "", line 1, in next(iL3) NameError: name 'iL3' is not defined >>> next(iL) 1 >>> for e in L: #creats the iterator for L and starts calling next print(e) 1 5 7 2 >>> g = countdown_gen() >>> type(g) >>> next(g) 5 >>> next(g) 4 >>> next(g) 3 >>> next(g) 2 >>> next(g) 1 >>> next(g) 'launch' >>> next(g) Traceback (most recent call last): File "", line 1, in next(g) StopIteration >>> g2 = countdown_gen() >>> for e in g2: print(e) 5 4 3 2 1 launch >>> countdown_gen() >>> >>> L = Evens_list(10**8) Traceback (most recent call last): File "", line 1, in L = Evens_list(10**8) File "C:\Documents and Settings\eladlibm\Desktop\T10\A10_iterators.py", line 13, in Evens_list return [num for num in range(n) if num%2==0] File "C:\Documents and Settings\eladlibm\Desktop\T10\A10_iterators.py", line 13, in return [num for num in range(n) if num%2==0] MemoryError #too much memory for my old lap! >>> L = Evens_list(10**8//2) #memory usage goes up >>> for e in L: pass >>> del L #memory down >>> L2 = Evens_gen(10**8) #memory usage does not go up >>> for e in L2: pass >>> g = (num for num in range(10**8) if num%2==0) #generator expression >>> next(g) 0 >>> type(g) >>> Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> >>> join_many(im, add(im,30)).display() >>> join_many(im, negate(im)).display() >>> join_many(im, what(im)).display() >>> join_many(im, upside_down(im)).display() >>> ================================ RESTART ================================ >>> ########################## ## we werote this in class def upside_down2(im): n,m = im.dim() im2 = Matrix(n,m) im2.rows = im.rows[:] im2.rows.reverse() return im2 ########################## >>> >>> join_many(im, upside_down2(im)).display() >>> join_many(im, upside_down_self(im)).display() >>> ================================ RESTART ================================ >>> >>> join_many(im, shift(im,50)).display() >>> join_many(im, stretch(im,'h',2)).display() >>>