How in Scala to find unique items in List

前端 未结 8 941
既然无缘
既然无缘 2020-12-04 17:14

How in Scala to find unique items in List?

8条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 17:51

    Imho, all the interpretations of the question are false:

    How in Scala to find unique items in List?

    Given this list:

    val ili = List (1, 2, 3, 4, 4, 3, 1, 1, 4, 1) 
    

    the only unique item in the list is 2. The other items aren't unique.

    ili.toSet.filter (i => ili.indexOf (i) == ili.lastIndexOf (i))
    

    will find it.

提交回复
热议问题