x = x = [i*2 for i in [j+1 for j in range(20) if (j%3) == 0] if i*i > 19] print x [14, 20, 26, 32, 38] y = [j+1 for j in range(20) if (j%3) == 0] print y [1, 4, 7, 10, 13, 16, 19] fruit = ["kiwi", "lemon", "peach", "somereallylongfruit", "grape"] x = [f for f in fruit if len(f)==max([len(f) for f in fruit])][0] print x grape # Don't use the same variable for both list comprehensions! # This answer is wrong and weird! y = [f for f in fruit if len(f)==max([len(v) for v in fruit])][0] print y somereallylongfruit # this time I used two variables, f and v z = [len(v) for v in fruit] print z [4, 5, 5, 19, 5] fruit = ["apple", "peach", "kiwi", "lemon", "lime"] y = [f for f in fruit if len(f)==max([len(v) for v in fruit])][0] print y apple colorlist = ['red', 'blue', 'red', 'red, 'green'] File "", line 1 colorlist = ['red', 'blue', 'red', 'red, 'green'] ^ SyntaxError: invalid syntax colorlist = ['red', 'blue', 'red', 'red', 'green'] print colorlist ['red', 'blue', 'red', 'red', 'green'] colorset = set(colorlist) print colorset set(['blue', 'green', 'red']) colorset.add("red") print colorset set(['blue', 'green', 'red']) colorset.add("yellow") print colorset set(['blue', 'green', 'yellow', 'red']) x = list(colorset) print x ['blue', 'green', 'yellow', 'red'] colorset.remove('yellow') print colorset set(['blue', 'green', 'red']) colorset.remove("purple") Traceback (most recent call last): File "C:\Users\Susan\AppData\Local\Enthought\Canopy\User\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 colorset.remove("purple") KeyError: 'purple'