python技巧——list comprehension vs map

>>>words = 'The quick brown fox jumps over the lazy dog'.split()
>>>stuff = [[w.upper(), w.lower(), len(w)] for w in words]
>>>stuff2 = map([w.upper(), w.lower(), len(w)], words)

两者可完成相似的功能,在list comprehension所不能使用的场合(比如创建规则过于复杂已致不能通过“for”和“if”完成,或者创建规则会随着时间动态变化),就需要使用map,反之亦然。(具体的例子,留待以后的总结吧)

你可能感兴趣的:(python技巧——list comprehension vs map)