eastlakeside / interpy-zh

📘《Python进阶》(Intermediate Python - Chinese Version)
https://py.eastlakeside.cn
Apache License 2.0
6.45k stars 1.33k forks source link

Filter章节中的一些疑问 #18

Closed oucb closed 8 years ago

oucb commented 8 years ago
less_than_zero = list(filter(lambda x: x < 0, number_list))

filter本身会生成一个列表,是否可以去掉list

suqi commented 8 years ago

感谢 @oucb 的建议, 这里确实不需要转换成list,去掉后看起来更简明清晰

原著里是这样,我觉得我们可以先于原著改进下,然后再给原著提过去

你来提个PR不? :) 看看要不要顺便对filter稍微多解释一句

filter(function or None, sequence) -> list, tuple, or string

Return those items of sequence for which function(item) is true. If function is None, return the items that are true. If sequence is a tuple or string, return the same type, else return a list.

oucb commented 8 years ago

已提PR。调整了下解释~@suqi