>>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version)) /Library/Frameworks/Python.framework/Versions/7.2/Resources/Python.app/Contents/MacOS/Python 2.7.2 |EPD 7.2-1 (32-bit)| (default, Sep 7 2011, 09:16:50) [GCC 4.0.1 (Apple Inc. build 5493)] >>> s = raw_input() this is so cool! Duke Wins! >>> s 'this is so cool! Duke Wins!' >>> type(s) >>> n = raw_input() 57 >>> type(n) >>> xx = int(n) >>> xx 57 >>> type(xx) >>> str(57) '57' >>> str('apple') 'apple' >>> int('apple') Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: 'apple' >>> int("57") 57 >>> >>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version)) /Library/Frameworks/Python.framework/Versions/7.2/Resources/Python.app/Contents/MacOS/Python 2.7.2 |EPD 7.2-1 (32-bit)| (default, Sep 7 2011, 09:16:50) [GCC 4.0.1 (Apple Inc. build 5493)] >>> s = [2,3,5,2,2] >>> s.count(2) 3 >>> s = [1,2,2,3,6] >>> max(1,2,3,4,5) 5 >>> max(5,6,3,2,7,8,1,1,1,) 8 >>> s = [1,2,2,2,5,4] >>> words = ["bear", "ant", "cat", "elephant"] >>> len(words) 4 >>> words[0] 'bear' >>> words[-1] 'elephant' >>> words ['bear', 'ant', 'cat', 'elephant'] >>> [w[0] for w in words] ['b', 'a', 'c', 'e'] >>> [w[1] for w in words] ['e', 'n', 'a', 'l'] >>> [w[len(w)-1] for w in words] ['r', 't', 't', 't'] >>> [w[-1] for w in words] ['r', 't', 't', 't'] >>> [w[17] for w in words] Traceback (most recent call last): File "", line 1, in IndexError: string index out of range >>> [w[4] for w in words] Traceback (most recent call last): File "", line 1, in IndexError: string index out of range >>> [w[2] for w in words] ['a', 't', 't', 'e'] >>> words ['bear', 'ant', 'cat', 'elephant'] >>> [w[len(w)-1] for w in words] ['r', 't', 't', 't'] >>> [w[-1] for w in words] ['r', 't', 't', 't'] >>> words ['bear', 'ant', 'cat', 'elephant'] >>> [w for w in words if len(w) > 2] ['bear', 'ant', 'cat', 'elephant'] >>> [w for w in words if len(w) > 3] ['bear', 'elephant'] >>> >>> >>> [1 for w in words if len(w) > 3] [1, 1] >>> toss = [3,2,5,3,5] >>> >>> >>> >>> >>> >>> >>> toss [3, 2, 5, 3, 5] >>> >>> >>> >>> >>> >>> range(1,7) [1, 2, 3, 4, 5, 6] >>> toss [3, 2, 5, 3, 5] >>> [toss[i] for i in range(1,7)] Traceback (most recent call last): File "", line 1, in IndexError: list index out of range >>> [toss.count(i) for i in range(1,7)] [0, 1, 2, 0, 2, 0] >>> [toss.count(i) for i in toss] [2, 1, 2, 2, 2] >>> toss [3, 2, 5, 3, 5] >>> [i*toss.count(i) for i in toss] [6, 2, 10, 6, 10] >>> [i*toss.count(i) for in range(1,7)] File "", line 1 [i*toss.count(i) for in range(1,7)] ^ SyntaxError: invalid syntax >>> [i*toss.count(i) for i in range(1,7)] [0, 2, 6, 0, 10, 0] >>> >>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version)) /Library/Frameworks/Python.framework/Versions/7.2/Resources/Python.app/Contents/MacOS/Python 2.7.2 |EPD 7.2-1 (32-bit)| (default, Sep 7 2011, 09:16:50) [GCC 4.0.1 (Apple Inc. build 5493)] >>> s = [2,3,5,2,2] >>> s.count(2) 3 >>> s = [1,2,2,3,6] >>> max(1,2,3,4,5) 5 >>> max(5,6,3,2,7,8,1,1,1,) 8 >>> s = [1,2,2,2,5,4] >>> words = ["bear", "ant", "cat", "elephant"] >>> len(words) 4 >>> words[0] 'bear' >>> words[-1] 'elephant' >>> words ['bear', 'ant', 'cat', 'elephant'] >>> [w[0] for w in words] ['b', 'a', 'c', 'e'] >>> [w[1] for w in words] ['e', 'n', 'a', 'l'] >>> [w[len(w)-1] for w in words] ['r', 't', 't', 't'] >>> [w[-1] for w in words] ['r', 't', 't', 't'] >>> [w[17] for w in words] Traceback (most recent call last): File "", line 1, in IndexError: string index out of range >>> [w[4] for w in words] Traceback (most recent call last): File "", line 1, in IndexError: string index out of range >>> [w[2] for w in words] ['a', 't', 't', 'e'] >>> words ['bear', 'ant', 'cat', 'elephant'] >>> [w[len(w)-1] for w in words] ['r', 't', 't', 't'] >>> [w[-1] for w in words] ['r', 't', 't', 't'] >>> words ['bear', 'ant', 'cat', 'elephant'] >>> [w for w in words if len(w) > 2] ['bear', 'ant', 'cat', 'elephant'] >>> [w for w in words if len(w) > 3] ['bear', 'elephant'] >>> >>> >>> [1 for w in words if len(w) > 3] [1, 1] >>> toss = [3,2,5,3,5] >>> >>> >>> >>> >>> >>> >>> toss [3, 2, 5, 3, 5] >>> >>> >>> >>> >>> >>> range(1,7) [1, 2, 3, 4, 5, 6] >>> toss [3, 2, 5, 3, 5] >>> [toss[i] for i in range(1,7)] Traceback (most recent call last): File "", line 1, in IndexError: list index out of range >>> [toss.count(i) for i in range(1,7)] [0, 1, 2, 0, 2, 0] >>> [toss.count(i) for i in toss] [2, 1, 2, 2, 2] >>> toss [3, 2, 5, 3, 5] >>> [i*toss.count(i) for i in toss] [6, 2, 10, 6, 10] >>> [i*toss.count(i) for in range(1,7)] File "", line 1 [i*toss.count(i) for in range(1,7)] ^ SyntaxError: invalid syntax >>> [i*toss.count(i) for i in range(1,7)] [0, 2, 6, 0, 10, 0] >>> >>> s = [3,3,5,5,5] >>> s [3, 3, 5, 5, 5] >>> range(1,7) [1, 2, 3, 4, 5, 6] >>> t = [s.count(e) for e in range(1,7)] >>> t [0, 0, 2, 0, 3, 0] >>> t = [e*s.count(e) for e in range(1,7)] >>> t [0, 0, 6, 0, 15, 0] >>> s [3, 3, 5, 5, 5] >>> s = [3,3,3,5,5] >>> t = [e*s.count(e) for e in range(1,7)] >>> t [0, 0, 9, 0, 10, 0] >>> [e*s.count(e) for e in s] [9, 9, 9, 10, 10] >>> >>> ls = ['abc', 'abc', 'abc', 'defg', 'defg', 'abc'] >>> len(ls) 6 >>> ls ['abc', 'abc', 'abc', 'defg', 'defg', 'abc'] >>> s = set(ls) >>> s set(['abc', 'defg']) >>> len(s) 2 >>> d = "dog" >>> d 'dog' >>> sorted(d) ['d', 'g', 'o'] >>> ''.join(sorted(d)) 'dgo' >>> d 'dog' >>> sorted('god') ['d', 'g', 'o'] >>> sorted('dgo') ['d', 'g', 'o'] >>>