+ 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
3 Answers
+ 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
+ 6
Thank you rodwynnejones and Rik Wittkopp âș
+ 3
arr = ["rolf", "golf", "solf", "rock", "and", "roll"]
val = filter(lambda name: name.startswith("r"), arr)
for x in val:
print(x)