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 Answers
+ 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
ļ½ļ½‚ļ½ˆļ½‰ļ½Žļ½ļ½–
ļ½ļ½‚ļ½ˆļ½‰ļ½Žļ½ļ½– - 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