我有一个包含10,000个项目和许多重复项目的列表框!我想把它保存到没有重复项目的文件(一个项目而不是所有副本!)并且我使用这种方式:
Function TMain.List_ExistsIn(ListBox_NAme: TListBox; EParameter: String): Integer;
Var
i: Integer;
Begin
EParameter := LowerCase(EParameter);
Result := -1;
For i:=0 To ListBox_Name.Items.Count - 1 Do
If EParameter = Lowercase(ListBox_Name.Items[i]) Then Begin
Result := i;
Break;
End;
End;
Run Code Online (Sandbox Code Playgroud)
我使用上面的代码来检测现有项目并按照以下步骤保存它:
Procedure TMain.MakeList(ListBox_Name: TListBox; FileName: String); //================
Var
i: Integer;
Temp_ListBox: TListBox;
Begin
Temp_ListBox := TListBox.Create(Main);
With Temp_ListBox Do Begin
Parent := Main;
Clear;
For i:=0 To ListBox_Name.Count - 1 Do
If Main.List_ExistsIn(Temp_ListBox, ListBox_Name.Items[i]) = -1 Then
Items.Add(ListBox_Name.Items[i]);
Items.SaveToFile(FileName);
Free;
End;
End;
Run Code Online (Sandbox Code Playgroud)
但它需要很长时间才能继续.有没有更好更快的方法?谢谢.
是否可以创建一个函数来创建一个带有列表输入的集合.
没有使用递归我只是想不出任何办法.
我可以使用高阶函数,如折叠,滤镜,地图,zip.我只是无法在我的函数中进行递归.
显然我不能使用小块.
我一直在试图弄清楚如何摆脱重复没有递归或任何类型的循环(至少我不认为我们可以使用循环,要问).
我的问题与此类似.基本上有一个CSV文件,但有重复的PID,但我不能这样做.uniq:
File.open("new.csv", "w+") { |file| file.puts File.readlines("old.csv").uniq }
Run Code Online (Sandbox Code Playgroud)
因为线条不同.我是Ruby的新手,想知道是否有一种优雅的方法可以根据第一列删除整行?或者我是否必须遍历每一行并查找重复的PID?
我正在尝试为我的 java 入门课程解决一个作业问题,我们应该在不使用集合或 .contains() 方法的情况下从列表中删除重复的项目。基本上只是使用迭代器和 .equals() 方法。我的代码如下:
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class sample {
public static void main(String[] args) throws BadListException {
List<String> myList = new ArrayList<String>();
myList.add("A");
myList.add("B");
myList.add("B");
myList.add("C");
myList.add("B");
myList.add("D");
unique(myList);
System.out.println(myList);
}
public static List<String> unique( List<String> items ) throws BadListException {
List<String> newList = new ArrayList<String>();
Iterator<String> itr = items.listIterator();
// If items is null, throw a BadListException.
if (items == null){
throw new BadListException();
}
// If items is empty, return …Run Code Online (Sandbox Code Playgroud) 我有没有ID的产品清单(300万件) - 只有标题.但我不知道DB中已存在哪些标题.必须在DB中添加新产品(约290万件).之后,我必须知道每种产品(新的和现有的)的ID.
在PostgreSQL中有最快的方法吗?我可以根据需要更改数据库(添加默认值,添加列等).
我想在这里提出的问题是:
无论如何我可以从下面的数组中删除连续的重复项,而只保留第一个?
数组如下所示:
$a=array("1"=>"go","2"=>"stop","3"=>"stop","4"=>"stop","5"=>"stop","6"=>"go","7"=>"go","8"=>"stop");
Run Code Online (Sandbox Code Playgroud)
我想要的是一个包含以下内容的数组:
$a=array("1"=>"go","2"=>"stop","3"=>"go","7"=>"stop");
Run Code Online (Sandbox Code Playgroud)
任何建议都会有帮助.问候.
我有一个列表列表,需要删除所有具有相同第三元素的列表,并保存1.
例如:
x=[[1,2,3],[1,3,3],[5,6,3],[2,4,6],[8,5,9],[10,5,9]]
Run Code Online (Sandbox Code Playgroud)
可以变成:
x=[[1,2,3],[2,4,6],[8,5,9]]
Run Code Online (Sandbox Code Playgroud)
我试过一个解决方案,使用lambda消除所有具有相同第二个索引的列表,但我不知道如何保存每个元素之一,如set()呢 - 我得到:
x=[[2,4,6]]
Run Code Online (Sandbox Code Playgroud) 我有一个浮点数的std :: vector我想不包含重复项,但是填充向量的数学运算不是100%精确的.向量的值相差几百,但应视为相同的点.例如,这里有一些值:
...
X: -43.094505
X: -43.094501
X: -43.094498
...
Run Code Online (Sandbox Code Playgroud)
从这样的向量中删除重复项的最佳/最有效方法是什么.
我有以下结构.我想将结构存储在矢量中.其次我想删除(context)上的重复值.我究竟做错了什么?
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//Structure
struct contextElement
{
string context;
float x;
};
int main()
{
vector<contextElement> v1;
v1.push_back({"1",1.0});
v1.push_back({"2",2.0});
v1.push_back({"1",1.0});
v1.push_back({"1",1.0});
//ERROR here
auto comp = [] ( const contextElement& lhs, const contextElement& rhs ) {return lhs.context == rhs.context;};
//Remove elements that have the same context
v1.erase(std::unique(v1.begin(), v1.end(),comp));
for(size_t i = 0; i < v1.size();i++)
{
cout << v1[i].context <<" ";
}
cout << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
错误:
main.cpp | …
我试图用来duplicated查找数据帧中仅基于两列重复的行.
当我将任何内容传递给incomparables参数时,我得到了错误
dups = duplicated(data, incomparables="Age")
...
argument 'incomparables != FALSE' is not used (yet)
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚这一点.
这个问题似乎有类似的问题,没有回应.
毫无疑问,有一种不同的方式来做同样的事情,这也很好知道,因为我是R的初学者.