duplicates

Python : How to find duplicates in a list and update these duplicate items by renaming them with a progressive letter added

人走茶凉 提交于 2019-12-02 12:54:14
I have a list of items like this: ['T1','T2','T2','T2','T2','T3','T3' ] I need to make sure that duplicates are renamed with a progressive letter added like this: ['T1','T2A','T2B','T2C','T2D','T3A','T3B'] but only if there is more than 1 occurrence of the same item. Also, is it possible to do so without generating a new list? Any ideas? from collections import Counter from string import ascii_uppercase as letters def gen(L): c = Counter(L) for elt, count in c.items(): if count == 1: yield elt else: for letter in letters[:count]: yield elt + letter Now: >>> L = ['T1','T2','T2','T2','T2','T3',

Removing duplicates in xsl

柔情痞子 提交于 2019-12-02 12:45:59
I have the following XML and I want to process it so that I do not get duplicates in the result set. I have simplified the problem to make it easier to understand. Also how can I use the results of one template as part of the input for another? This: <LINES xmlns:set="http://exslt.org/sets"> <STDINSTRSEQ>0</STDINSTRSEQ> <STDINSTRSEQ>1</STDINSTRSEQ> <STDINSTRSEQ>2</STDINSTRSEQ> </LINES> is the desired result. <STDINSTRSEQ> is the name of the field that should be treated as the key. I have provided the sample data here. <PURCHASEORDER> <POHEADER> <BODID>infor-nid:Elevon:SCMCS::12654_0198617S12

Remove consecutive duplicate characters from a string in python

半世苍凉 提交于 2019-12-02 12:11:33
问题 Hey I was trying to write a program which will remove the consecutive duplicate characters from a string. for example: string->aabbccde first iteration: bbccde second iteration: ccde third Iteration: de and de is the answer. following is the program I wrote. a = "aabbcs" def remove_dups(st,ind): print st, ind st = st.replace(st[ind], "") print st, "in dups" find_dups(st) def find_dups(text): s=text print s, "in find" ln = len(s) print ln fg = 0 ind = 0 if ln==1: print s, 'len' return s for i

Common elements between two lists with no duplicates

倖福魔咒の 提交于 2019-12-02 12:10:38
Problem is this, take two lists, say for example these two: a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] And write a program that returns a list that contains only the elements that are common between the lists (without duplicates). Make sure your program works on two lists of different sizes. Here's my code: a = [1, 1, 2, 2, 3, 5, 8, 13, 21, 34, 55, 89] b = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] c = [] for i in a: if i in b and i not in c: c.append([i]) print(c) My output is still giving me duplicates despite the 'i not in c' statement.

Why do I get an unhashable type 'list' error when converting a list to a set and back

∥☆過路亽.° 提交于 2019-12-02 11:43:33
Like many other questions on here, I'm attempting to remove duplicates from a list. However, when I execute code that other answers claim work I get the following error: TypeError: unhashable type: 'list' on the following line of code: total_unique_words = list(set(total_words)) Does anyone know a possible solution to this problem? Is this because in most cases the original structure isn't a list? Thanks! total_words must contain sublists for this error to occur. Consider: >>> total_words = ['red', 'red', 'blue'] >>> list(set(total_words)) ['blue', 'red'] >>> total_words = ['red', ['red',

In PHP, merge duplicate set of elements of an multidimensional array and sum the values of specific key

半城伤御伤魂 提交于 2019-12-02 11:19:48
I have following array where I am trying to merge the elements which has shelf and weight value as duplicate and sum the value of piece key. Array ( [0] => Array ( [shelf] => Left [weight] => 10.000 [piece] => 1 ) [1] => Array ( [shelf] => Right [weight] => 04.000 [piece] => 12 ) [2] => Array ( [shelf] => Right [weight] => 04.000 [piece] => 4 ) [3] => Array ( [shelf] => Right [weight] => 07.000 [piece] => 8 ) ) Currently I am getting following desired output with help of following SQL statement by creating the temporary table with following fields shelf , weight and piece and inserting all the

Getting duplicates with additional information

安稳与你 提交于 2019-12-02 11:17:34
I've inherited a database and I'm having trouble constructing a working SQL query. Suppose this is the data: [Products] | Id | DisplayId | Version | Company | Description | |---- |----------- |---------- |-----------| ----------- | | 1 | 12345 | 0 | 16 | Random | | 2 | 12345 | 0 | 2 | Random 2 | | 3 | AB123 | 0 | 1 | Random 3 | | 4 | 12345 | 1 | 16 | Random 4 | | 5 | 12345 | 1 | 2 | Random 5 | | 6 | AB123 | 0 | 5 | Random 6 | | 7 | 12345 | 2 | 16 | Random 7 | | 8 | XX45 | 0 | 5 | Random 8 | | 9 | XX45 | 0 | 7 | Random 9 | | 10 | XX45 | 1 | 5 | Random 10 | | 11 | XX45 | 1 | 7 | Random 11 |

Displaying duplicate row numbers

蓝咒 提交于 2019-12-02 11:12:38
I joined a table to itself to find duplicate rows select a.data, a.rowNumber, b.rowNumber from DuplicateRows as a join DuplicateRows as b on a.data = b.data and a.Id != b.Id group by a.data, a.rowNumber, b.rowNumber This query gives the results like "content" | 1 | 2 "content" | 1 | 6 "content" | 2 | 1 "content" | 2 | 6 ...and so on Howcome I rewrite it to have results formed like "content" | 1 | 2, 6 EDIT I think the question should be a little bit corrected. You see I don't want to get the inversed result, I mean I just want to get one entry `1 -> 2, 6` not `1 -> 2, 6 and `2 -> 1, 6` Thanks!

Definitive Fix for Android's bug of duplicating photo on gallery when using the internal camera

限于喜欢 提交于 2019-12-02 11:11:21
问题 This is definitive fix for the Android's problem of duplicating a photo. Tested it on 2.3 (which has the bug), 4.x (which doesnt have the bug) and 5.x (which has the bug too). The problem is that the photo is saved in two formats: usually one is the timestamp.jpg, and the other one is the full_date_and_time.jpg; sometimes in the same folder, sometimes in different folders. For example, "1430910805600.jpg" and "2015-05-06 11.14.00.jpg". Worstly, one cannot be converted to the other. 回答1: The

JavaFX : TableView inside Dialog has duplicate items

大憨熊 提交于 2019-12-02 11:04:20
I have an issue with my TableView and its items. I have created a small Dialog window to display warnings about my app, and inside the Dialog I have a TableView which displays the name of the warning and some information about it upon clicking on a button. I have created a WarningUtil class ( Singleton pattern) just to open / close the Dialog . The relevant code follows. The constructor of the WarningUtil class (called once only) : private WarningUtil(RootCtrl rootCtrl) { this.rootCtrl = rootCtrl; warnings = new HashMap<>(); setupWarningCallbacks(); // not relevant setupTable(); setupColumns()