擅长:python、mysql、java
<blockquote>
<p>Apply function to every item of iterable and return a list of the
results.</p>
</blockquote>
<p>来自<a href="http://docs.python.org/library/functions.html#map" rel="nofollow">the documentation for ^{<cd1>}</a></p>
<p><code>int()</code><em>尝试将传递的内容转换为整数,并将引发一个<code>ValueError</code>如果您尝试一些愚蠢的操作,例如:</p>
<pre><code>>>> int('Hello')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'Hello'
</code></pre>
<p><code>map()</code>将返回一个列表,该列表具有您要求它调用任何iterable的函数的返回值。如果您的函数不返回任何内容,那么您将得到一个<code>None</code>s的列表,如下所示:</p>
<pre><code>>>> def silly(x):
... pass
...
>>> map(silly,'Hello')
[None, None, None, None, None]
</code></pre>
<p>这是做这种事情的短而有效的方法:</p>
<pre><code> def verbose_map(some_function,something):
results = []
for i in something:
results.append(some_function(i))
return results
</code></pre>