我有一个表,我保存所有发生过的行更改.问题是,在应用程序的开头,有一个错误,每行都有一堆副本.
该表看起来像这样:
copies
|ID |CID |DATA
| 1 | 1 | DA
| 2 | 2 | DO
| 2 | 3 | DO (copy of CID 2)
| 1 | 4 | DA (copy of CID 1)
| 2 | 5 | DA
| 1 | 6 | DA (copy of CID 1)
| 2 | 7 | DO
Run Code Online (Sandbox Code Playgroud)
表副本中的CID是唯一的.
我想要的是删除按CID排序的所有DATA GROUP BY ID重复项.
正如您在表中看到的那样,CID 2和3是相同的,它们是相继的.我想删除CID 3.与CID 4和CID 6相同; 他们之间没有ID 1,是CID 1的副本.
重复删除后,我希望表格看起来像这样:
copies
|ID |CID |DATA
| 1 …Run Code Online (Sandbox Code Playgroud) 我有一个用 6 个随机生成的数字填充的数组。首先,它生成一个 1 到 49 之间的随机数,然后根据数组中的数字进行检查。如果发现重复,它应该再次生成一个随机数,然后再次执行检查。如果没有重复,则将数字添加到数组中。
这是代码:
public void populateArray()
{
for(int i = 0; i < numberLine.length; i++)
{
randomNumber = 1 + randomGen.nextInt(49);
for(int j = 0; j < i; j++)
{
if (numberLine[j] == randomNumber)
{
i--;
}
else
{
continue;
}
}
if(i >= 0)
{
numberLine[i] = randomNumber;
}
else
{
continue;
}
}
Arrays.sort(numberLine);
}
Run Code Online (Sandbox Code Playgroud)
但是,出于某种原因,这仍然允许重复,尽管很少(大约 50 个数组中的 1 个),例如6 6 16 24 34 46. 但是当我尝试通过取出随机数元素并使用像 30 这样的数字来复制它时,我无法重现结果。怎么了?
-53 45
-54 43
-55 42
-56 41
-57 40
-59 37
-61 35
-61 36
-62 34
-64 33
-65 31
-65 32
-67 30
-68 29
-69 28
-72 25
-73 23
-73 24
-74 22
-76 20
-76 22
-78 20
-79 18
-80 17
-81 16
Run Code Online (Sandbox Code Playgroud)
在上面你会看到-61出现两次,所以做其他一些值.我想创建一个没有任何重复的新文件.所以新文件应该有-61 35或-61 36 ......
我怎么做?!我尝试使用uniq使用sort但是没有用.
我在这个结构中有一个自定义对象
static class Node {
int col;
int row;
int g;
int h;
int f;
public Node(int col, int row, int g, int h) {
this.col = col;
this.row = row;
this.g = g;
this.h = h;
this.f = g+h;
}
}
Run Code Online (Sandbox Code Playgroud)
在col和row变量是独一无二的,可一次只发生ArrayList<Node> myList。
有没有一种最佳方法可以避免添加或检查可能的重复项而不必进行令人讨厌的 for 循环?
我知道Set接口可能是一个解决方案,因为不会发生重复,但我现在有很多代码,除非有必要,否则我不想重构。
所以我有一些文件看起来像:
snpID Gene
rs1 ABC1
rs2 ABC1
rs3 ABC25
rs4 PT4
rs5 MTND24
Run Code Online (Sandbox Code Playgroud)
在不同的文件中,将存在其他snpID和基因对,但是对于给定的snpID可能存在重复,但相关联的"基因"可能不同.例如:
snpID Gene
rs100 URX1
rs95 KL4
rs1 ABC1
rs2 ABC1-MHT5
rs3 ABC25
rs4 PT4-FIL42
Run Code Online (Sandbox Code Playgroud)
我想要做的是附加文件的所有内容,如果它们具有相同的snpID和Gene对,则删除重复项.然而,如果snpID的相应基因不同,则它必须进入同一行.对于上面的示例,它应该如下所示:
snpID Gene
rs1 ABC1
rs2 ABC1, ABC1-MHT5
rs3 ABC25
rs4 PT4, PT4-FIL42
rs5 MTND2
rs100 URX1
rs95 KL4
Run Code Online (Sandbox Code Playgroud)
我以为我可以通过创建词典来实现这一目标.
import glob
file_list = glob.glob('annotations.*')
dict_snps_genes = {}
for filename in file_list:
with open(filename) as fileA:
for line in fileA:
col0 = line.split()[0]
col1 = line.split()[1]
dict_snps_genes[col0] = col1
unique_dict_snps = {} …Run Code Online (Sandbox Code Playgroud) 我想知道是否有人碰到以下内容:
SQL查询:
SELECT s.ID , s.name , s.artist, m.tag_ID, t.name, s.*, m.*, t.*
FROM lms_song s
LEFT JOIN lms_map m
ON s.ID = m.ID
LEFT JOIN lms_tag t
ON m.tag_id = t.ID
WHERE s.created_by='.$userId.'
ORDER BY '.$Field.' '.$Direction;
Run Code Online (Sandbox Code Playgroud)
PHP:
<? foreach($this->songs AS $song){ ?>
<tr>
<td>
<?php echo $song->songName;?>
</td>
<td>
<?php echo $song->artist;?>
</td>
<td>
<?php echo $song->tagname;?>
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
它当前显示用户列出的所有"歌曲".
虽然它确实列出了与用户相关的所有歌曲,但它具有多个歌曲名称重复,因为每个歌曲名称都有与之关联的标签.
我试图只为"歌曲名称"显示"Group By s.name".
但是,这将其限制为一个t.name(标记).
我希望每个艺术家(s.artist)不显示歌曲名称(s.name)的重复,同时显示与其关联的所有标签(t.name).
任何帮助表示赞赏.
谢谢!
我有3个子类"Staff,Faculty,Student",每个类从父类人员那里得到用户的第一个姓氏,这个id就像在运行控制台应用程序时添加4个随机数.我遇到的问题是所有的类都得到相同的4位数,我该如何解决这个问题,是的,必须使用随机我不能使用静态计数器.
Person.cs"父类"
public class Person
{
static string title;
protected string firstName;
protected string lastName;
protected string address;
protected string gender;
protected string dateOfBirth;
protected string userID;
protected Random rnd = new Random();
Run Code Online (Sandbox Code Playgroud)
Faculty.cs
namespace Person
{
public class Faculty : Person
{
public Faculty(string aTitle, string aFirstName, string aLastName, string aAddress,
string aGender, string aDateOfBirth)
: base(aTitle, aFirstName, aLastName, aAddress,
aGender, aDateOfBirth)
{
this.userID = firstName.Substring(0, 1) + lastName.Substring(0, 5);
this.userID = this.userID + rnd.Next(1000, 9999);
Console.WriteLine(this.userID);
}
} …Run Code Online (Sandbox Code Playgroud) 有没有办法将重复的字符减少到特定的数字,例如,如果我们有这个字符串.
"I liiiiked it, thaaaaaaank you"
预期产量: "I liiiiked it thaaaank you"
因此,如果重复的字符超过4,例如,它应该减少到只有4个字符,如果它小于或等于4,那么该字应该保持不变.
我已经尝试了各种各样的PHP逻辑和PHP的内置函数来删除重复的值,但它不工作没有错误显示但是如果用于array_unique() in_array()删除我的数组中的重复对象,我的所有JQuery和CSS都不起作用
这就是我person_row_array在while循环中创建的方式:
$person_row = Person::findByID($pi_claimant_row->person_id);
$person_row_array[] = $person_row;
Run Code Online (Sandbox Code Playgroud)
对象print_r如下:
Array
(
[0] => stdClass Object
(
[id] => 12
[flat_no] =>
[house_no] => *
[street] =>
[town] =>
[postcode] => *
[county] =>
)
[1] => stdClass Object
(
[id] => 14
[flat_no] => 2
[house_no] => 33
[street] => Street
[town] => Town
[postcode] => BB
[county] => County
)
[2] => stdClass Object
(
[id] => 14
[flat_no] => 2
[house_no] => 33 …Run Code Online (Sandbox Code Playgroud) 如果我有这样一个列表:
mylist = [[1,2,3], ['a', 'c'], [3,4,5],[1,2], [3,4,5], ['a', 'c'], [3,4,5], [1,2]]
Run Code Online (Sandbox Code Playgroud)
删除重复子列表的最佳方法是什么?
现在我用这个:
y, s = [ ], set( )
for t in mylist:
w = tuple( sorted( t ) )
if not w in s:
y.append( t )
s.add( w )
Run Code Online (Sandbox Code Playgroud)
它有效,但我想知道是否有更好的方法?更蟒蛇般的东西?