# 获取一个map（）来返回Python 3.x中的一个列表

``>>> map(chr, [66, 53, 0, 94]) ['B', '5', '\x00', '^']` `

B： Python 3.1：

` `>>> map(chr, [66, 53, 0, 94]) <map object at 0x00AF5570>` `

` `list(map(chr,[66,53,0,94]))` `

` `# Prints "ABCD" for ch in map(chr,[65,66,67,68]): print(ch)` `

` `[chr(x) for x in [66,53,0,94]]` `

Python 3.5中新的和整洁的：

` `[*map(chr, [66, 53, 0, 94])]` `

` `lmap = lambda func, *iterable: list(map(func, *iterable)` `

` `__global_map = map #keep reference to the original map lmap = lambda func, *iterable: list(__global_map(func, *iterable)) # using "map" here will cause infinite recursion map = lmap x = [1, 2, 3] map(str, x) #test map = __global_map #restore the original map and don't do that again map(str, x) #iterator` `

` `[chr(x) for x in [66, 53, 0, 94]]` `
` `list(map(chr, [66, 53, 0, 94]))` `

map（func，* iterables） – > map对象创建一个迭代器，使用来自每个迭代器的参数来计算函数。 当最短的迭代器耗尽时停止。

“做一个迭代器”

“使用来自每个可迭代的参数来计算函数”

` `>>> %%timeit -r5 ordinals = list(range(45)) ... list(map(chr, ordinals)) ... 3.91 µs ± 60.2 ns per loop (mean ± std. dev. of 5 runs, 100000 loops each) >>> %%timeit -r5 ordinals = list(range(45)) ... [*map(chr, ordinals)] ... 3.84 µs ± 219 ns per loop (mean ± std. dev. of 5 runs, 100000 loops each) >>> %%timeit -r5 ordinals = list(range(45)) ... [*bytes(ordinals).decode('ascii')] ... 1.43 µs ± 49.7 ns per loop (mean ± std. dev. of 5 runs, 1000000 loops each) >>> %%timeit -r5 ordinals = list(range(45)) ... bytes(ordinals).decode('ascii') ... 781 ns ± 15.9 ns per loop (mean ± std. dev. of 5 runs, 1000000 loops each)` `