li = [1,2,3,4,5,6,7,8,9] print [x**2 for x in li]
必须使用[],不然容易报错
mcase = {'a': 10, 'b': 34} mcase_frequency = {v: k for k, v in mcase.items()} print mcase_frequency # Output: {10: 'a', 34: 'b'}
squared = {x**2 for x in [1, 1, 2]} print(squared) # Output: set([1, 4])