0

Whats the logic of print the answer out?

scores = [88,90,40,60,65,91,98] a_score = filter(lambda i : True if i >= 90 else False, scores) for k in a_score: print(k) Whyl it would result an error if directly print the "a_score" out, as well as need to use for..in loop to print it out?

26th Oct 2020, 1:55 AM
Joe Ma
Joe Ma - avatar
4 ответов
+ 1
a_score is not a list, so you cannot print it directly until a conversion. This is also mentioned in the lessons https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2461/
26th Oct 2020, 3:09 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 1
It creates a filter object (like a generator) and not a list. Remember that such objects are iterable (but cannot be indexed). You need to make it into a list to print it out. a_score = list(filter( ... ))
26th Oct 2020, 3:09 AM
abhinav
abhinav - avatar
+ 1
CarrieForle I see, I havent been there (the lesson)before. Thanks a lot!
26th Oct 2020, 3:11 AM
Joe Ma
Joe Ma - avatar
+ 1
Abhinav Anand Good! Thank you so much!
26th Oct 2020, 3:12 AM
Joe Ma
Joe Ma - avatar