duplicates

How do I remove duplicate characters and keep the unique one only in Perl?

£可爱£侵袭症+ 提交于 2019-11-26 20:31:23
问题 How do I remove duplicate characters and keep the unique one only. For example, my input is: EFUAHUU UUUEUUUUH UJUJHHACDEFUCU Expected output is: EFUAH UEH UJHACDEF I came across perl -pe's/$1//g while/(.).*\/' which is wonderful but it is removing even the single occurrence of the character in output. 回答1: This can be done using positive lookahead : perl -pe 's/(.)(?=.*?\1)//g' FILE_NAME The regex used is: (.)(?=.*?\1) . : to match any char. first () : remember the matched single char. (?=..

remove duplicate from string in PHP

柔情痞子 提交于 2019-11-26 20:08:31
I am looking for the fastest way to remove duplicate values in a string separated by commas. So my string looks like this; $str = 'one,two,one,five,seven,bag,tea'; I can do it be exploding the string to values and then compare, but I think it will be slow. what about preg_replace() will it be faster? Any one did it using this function? The shortest code would be: $str = implode(',',array_unique(explode(',', $str))); If it is the fastest... I don't know, it is probably faster then looping explicitly. Reference: implode , array_unique , explode Dealing with: $string = 'one,two,one,five,seven,bag

How can i duplicate a div onclick with javascript?

时光总嘲笑我的痴心妄想 提交于 2019-11-26 19:52:31
问题 I want a div to be duplicated when a button is clicked. I though something like this; but it's not working. Can anyone help me? HTML <div id="duplicater"> duplicate EVERYTHING INSIDE THIS DIV </div> JAVASCRIPT function duplicate() { var div = duplicate("div"); div.id = "duplicater"; div.appendChild(duplicate("duplicater")); } 回答1: You are creating an infinite recursion! function duplicate() { var div = duplicate("div"); The function is calling itself over and over again. Use cloneNode(): HTML

Fastest way to remove duplicate documents in mongodb

六月ゝ 毕业季﹏ 提交于 2019-11-26 19:43:58
I have approximately 1.7M documents in mongodb (in future 10m+). Some of them represent duplicate entry which I do not want. Structure of document is something like this: { _id: 14124412, nodes: [ 12345, 54321 ], name: "Some beauty" } Document is duplicate if it has at least one node same as another document with same name . What is the fastest way to remove duplicates? Assuming you want to permanently delete docs that contain a duplicate name + nodes entry from the collection, you can add a unique index with the dropDups: true option: db.test.ensureIndex({name: 1, nodes: 1}, {unique: true,

pandas group by year, rank by sales column, in a dataframe with duplicate data

ぐ巨炮叔叔 提交于 2019-11-26 19:38:25
问题 I would like to create a rank on year (so in year 2012, Manager B is 1. In 2011, Manager B is 1 again). I struggled with the pandas rank function for awhile and DO NOT want to resort to a for loop. s = pd.DataFrame([['2012','A',3],['2012','B',8],['2011','A',20],['2011','B',30]], columns=['Year','Manager','Return']) Out[1]: Year Manager Return 0 2012 A 3 1 2012 B 8 2 2011 A 20 3 2011 B 30 The issue I'm having is with the additional code (didn't think this would be relevant before): s = pd

Finding duplicate files and removing them

荒凉一梦 提交于 2019-11-26 19:21:54
I am writing a Python program to find and remove duplicate files from a folder. I have multiple copies of mp3 files, and some other files. I am using the sh1 algorithm. How can I find these duplicate files and remove them? Fastest algorithm - 100x performance increase compared to the accepted answer (really :)) The approaches in the other solutions are very cool, but they forget about an important property of duplicate files - they have the same file size. Calculating the expensive hash only on files with the same size will save tremendous amount of CPU; performance comparisons at the end,

MySQL ON DUPLICATE KEY UPDATE for multiple rows insert in single query

吃可爱长大的小学妹 提交于 2019-11-26 19:15:29
I have a SQL query where I want to insert multiple rows in single query. so I used something like: $sql = "INSERT INTO beautiful (name, age) VALUES ('Helen', 24), ('Katrina', 21), ('Samia', 22), ('Hui Ling', 25), ('Yumie', 29)"; mysql_query( $sql, $conn ); The problem is when I execute this query, I want to check whether a UNIQUE key (which is not the PRIMARY KEY ), e.g. 'name' above, should be checked and if such a 'name' already exists, the corresponding whole row should be updated otherwise inserted. For instance, in the example below, if 'Katrina' is already present in the database, the

Python json parser allow duplicate keys

廉价感情. 提交于 2019-11-26 19:09:56
I need to parse a json file which unfortunately for me, does not follow the prototype. I have two issues with the data, but i've already found a workaround for it so i'll just mention it at the end, maybe someone can help there as well. So i need to parse entries like this: "Test":{ "entry":{ "Type":"Something" }, "entry":{ "Type":"Something_Else" } }, ... The json default parser updates the dictionary and therfore uses only the last entry. I HAVE to somehow store the other one as well, and i have no idea how to do this. I also HAVE to store the keys in the several dictionaries in the same

data.table with two string columns of set elements, extract unique rows with each row unsorted

末鹿安然 提交于 2019-11-26 19:07:11
Suppose I have a data.table like this: Table: V1 V2 A B C D C A B A D C I want each row to be regarded as a set, which means that B A and A B are the same. So after the process, I want to get: V1 V2 A B C D C A In order to do that, I have to first sort the table row-by-row and then use unique to remove the duplicates. The sorting process is quite slow if I have millions of rows. So is there an easy way to remove the duplicates without sorting? For just two columns you can use the following trick: dt = data.table(a = letters[1:5], b = letters[5:1]) # a b #1: a e #2: b d #3: c c #4: d b #5: e a

How to find all duplicate from a List<string>? [duplicate]

北城以北 提交于 2019-11-26 19:04:01
问题 This question already has answers here : C# LINQ find duplicates in List (7 answers) Closed 3 months ago . I have a List<string> which has some words duplicated. I need to find all words which are duplicates. Any trick to get them all? 回答1: In .NET framework 3.5 and above you can use Enumerable.GroupBy which returns an enumerable of enumerables of duplicate keys, and then filter out any of the enumerables that have a Count of <=1, then select their keys to get back down to a single enumerable