TypeError: 'filter' object is not subscriptable

前端 未结 3 2115
囚心锁ツ
囚心锁ツ 2020-12-29 18:52

I am receiving the error

TypeError: \'filter\' object is not subscriptable

When trying to run the following block of code



        
3条回答
  •  独厮守ぢ
    2020-12-29 19:32

    Use list before filter condtion then it works fine. For me it resolved the issue.

    For example

    list(filter(lambda x: x%2!=0, mylist))
    

    instead of

    filter(lambda x: x%2!=0, mylist)
    

提交回复
热议问题