x = [2*x for x in range(10000)] print len(x) 10000 print x[:20] [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38] 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 y at 0x0000000003EF8F78> print sum(x) 99990000 print sum(y) 99990000 print sum(x) 99990000 print sum(y) 0 d = {"sam":3, "mary":10, "zhou":5} print d.keys() ['zhou', 'mary', 'sam'] print d.values() [5, 10, 3] print d.items() [('zhou', 5), ('mary', 10), ('sam', 3)] print d.iteritems() for x in d.iteritems(): print x ('zhou', 5) ('mary', 10) ('sam', 3) for x in d.iteritems(): print x ('zhou', 5) ('mary', 10) ('sam', 3) y = d.iteritems() for x in y: print x ('zhou', 5) ('mary', 10) ('sam', 3) for x in y: print x # nothing printed