How to return elements from a list that have a certain length?

后端 未结 5 917
一生所求
一生所求 2020-11-30 14:14

I\'m trying to return words that have a specific length size.

The words is a list and size is a positive integer here. The result should be

5条回答
  •  日久生厌
    2020-11-30 14:36

    return filter(lambda x: len(x)==size, words)
    

    for more info about the function, please see filter()

提交回复
热议问题