+ 5

Why iam not able to print the value of val?

arr = ["rolf","golf","solf"] val = filter(lambda name:name.starswith("r"),arr) print(next(val)) """Traceback (most recent call last): File "C:/Users/Aiyoo/.PyCharmCE2018.3/config/scratches/scratch_26.py", line 3, in <module> print(next(c)) File "C:/Users/Aiyoo/.PyCharmCE2018.3/config/scratches/scratch_26.py", line 2, in <lambda> c=filter(lambda name:name.starswith("r"),arr) AttributeError: 'str' object has no attribute 'starswith' """ https://code.sololearn.com/cOI5Q4d6O5Ii/?ref=app

7th Dec 2019, 6:46 PM
Vijay(v-star🌟)
Vijay(v-star🌟) - avatar
3 Respuestas
+ 3
2 errors: arr = ["rolf","golf","solf"] val = filter(lambda name: name.startswith("r"),(arr)) print(next(val)) Typo in startswith Lambda needed arr in parenthesis in order to assign value to name
7th Dec 2019, 7:54 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 6
Thank you rodwynnejones and Rik Wittkopp
8th Dec 2019, 1:06 PM
Vijay(v-star🌟)
Vijay(v-star🌟) - avatar
+ 3
arr = ["rolf", "golf", "solf", "rock", "and", "roll"] val = filter(lambda name: name.startswith("r"), arr) for x in val: print(x)
7th Dec 2019, 9:24 PM
rodwynnejones
rodwynnejones - avatar