#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
def map(func, seq):
mapped_seq = []
for eachItem in seq:
mapped_seq.append(func(eachItem))
return mapped_seq
'''
'''将传入的序列,每一个值都加2'''
print map((lambda x: x+2), [0, 1, 2, 3, 4, 5])
print [x+2 for x in range(6)]
print map(lambda x: x**2, range(6))
print [x**2 for x in range(6)]
输出:
D:\Python27\test>func16.py
[2, 3, 4, 5, 6, 7]
[2, 3, 4, 5, 6, 7]
[0, 1, 4, 9, 16, 25]
[0, 1, 4, 9, 16, 25]
D:\Python27\test>