Return list of items in list greater than some value

前端 未结 7 1803
故里飘歌
故里飘歌 2020-11-29 02:16

I have the following list

j=[4,5,6,7,1,3,7,5]

What\'s the simplest way to return [5,5,6,7,7] being the elements in j greater o

相关标签:
7条回答
  • 2020-11-29 03:02

    Since your desired output is sorted, you also need to sort it:

    >>> j=[4, 5, 6, 7, 1, 3, 7, 5]
    >>> sorted(x for x in j if x >= 5)
    [5, 5, 6, 7, 7]
    
    0 讨论(0)
提交回复
热议问题