Kotlin check list for duplicates
Ngày đăng:
20/12/2021
Trả lời:
0
Lượt xem:
194
This language bar is your friend. Select your favorite languages! Select your favorite languages :
Idiom #119 Deduplicate listRemove duplicates from the list x.
x = x.distinct()
x = x.toSet().toList()
(distinct x)
#include std::sort(x.begin(), x.end());
auto last = std::unique(x.begin(), x.end());
x.erase(last, x.end());
#include std::vector
using System.Collections.Generic;
using System.Linq; var uniques = x.Distinct().ToList(); import std.container;
import std.array; x = redBlackTree(x)[].array;
import std.algorithm;
import std.array; x = x.sort.uniq.array;
x = x.toSet().toList();
Enum.uniq(x)
S = lists:usort(X)
y := make(map[T]struct{}, len(x))
for _, v := range x {
y[v] = struct{}{}
}
x2 := make([]T, 0, len(y))
for _, v := range x {
if _, ok := y[v]; ok {
x2 = append(x2, v)
delete(y, v)
}
}
x = x2
seen := make(map[T]bool)
j := 0
for _, v := range x {
if !seen[v] {
x[j] = v
j++
seen[v] = true
}
}
for i := j; i < len(x); i++ {
x[i] = nil
}
x = x[:j]
seen := make(map[T]bool)
j := 0
for _, v := range x {
if !seen[v] {
x[j] = v
j++
seen[v] = true
}
}
x = x[:j]
x.unique()
import Data.List (sort) nub $ sort x x = Array.from(new Set(x));
const seen = new Set();
x = x.filter( v => {
if(seen.has(v))
return false;
seen.add(v);
return true;
});
x = [...new Set(x)];
import java.util.HashSet;
import java.util.ArrayList; x = new ArrayList import java.util.HashSet;
import java.util.List;
import java.util.Set; Set import java.util.HashSet;
import java.util.Iterator; final HashSet
(remove-duplicates x) local seen = {}
for index,item in ipairs(x) do
if seen[item] then
table.remove(x, index)
else
seen[item] = true
end
end @import Foundation; [NSSet setWithArray:x].allObjects $x = array_unique($x);
uses classes; var
x: TList;
begin
for i:= x.count-1 downto 0 do
if x.indexOf(x.items[i]) <> -1 then
x.delete(i);
end; use List::MoreUtils 'uniq'; @x = uniq(@x);
from collections import OrderedDict x = list(OrderedDict(zip(x, x)))
x = list(set(x)) x.uniq!
x.sort();
x.dedup();
use itertools::Itertools; let dedup: Vec<_> = x.iter().unique().collect();
x = x.distinct (define (remove-duplicates l)
(cond ((null? l)
'())
((member (car l) (cdr l))
(remove-duplicates (cdr l)))
(else
(cons (car l) (remove-duplicates (cdr l))))))
(remove-duplicates x)
x asSet. x intersection: x asSet. x = x.Distinct.ToList Do you know the best way to do this in your language ? New implementation... Idiom created by programming-idioms.org History
Cool Maze |