x = [2*x for x in range(10000)] print len(x) 10000 print x[:10] [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] print x[9990:] [19980, 19982, 19984, 19986, 19988, 19990, 19992, 19994, 19996, 19998] y = (2*x for x in range(10000)) print len(y) Traceback (most recent call last): File "C:\Users\Susan\AppData\Local\Enthought\Canopy\App\appdata\canopy-2.1.3.3542.win-x86_64\lib\site-packages\IPython\core\interactiveshell.py", line 2885, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in print len(y) TypeError: object of type 'generator' has no len() print sum(x) 99990000 print sum(y) 99990000 print sum(x) 99990000 print sum(y) 0 y = (2*x for x in range(10000)) print sum(y) 99990000 print sum(y) 0 d = {"joe":6, "moe":10, "zhou":3} print d.keys() ['zhou', 'joe', 'moe'] print d.values() [3, 6, 10] print d.items() [('zhou', 3), ('joe', 6), ('moe', 10)] print d.iteritems() for x in d.iteritems(): print x ('zhou', 3) ('joe', 6) ('moe', 10) y = d.iteritems() for x in y: print x ('zhou', 3) ('joe', 6) ('moe', 10) for s in y: print s # nothing is printed y = (2*x for x in range(10000)) print type(y) print y at 0x0000000003FE4120> for x in y: print x 0 2 4 ... lots of numbers