>>> 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] >>> 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] >>> w = "second" >>> w[0] 's' >>> w[1] 'e' >>> >>> w[:1] 's' >>> w[:2] 'se' >>> s = "this is a string" >>> s.split() ['this', 'is', 'a', 'string'] >>> [w[0] for w in s.split()] ['t', 'i', 'a', 's'] >>> s = "self contained underwater breathing apparatus" >>> [w[0] for w in s.split()] ['s', 'c', 'u', 'b', 'a'] >>> ':'.join([w[0] for w in s.split()]) 's:c:u:b:a' >>> ''.join([w[0] for w in s.split()]) 'scuba' >>> xx = "space " >>> len(xx) 6 >>> len(xx.strip()) 5 >>> xx.strip() 'space' >>> xx = ' strip ' >>> len(xx) 12 >>> len(xx.strip()) 5 >>> xx.strip() 'strip' >