sorting

How to find common keys in a list of dicts and sort them by value?

强颜欢笑 提交于 2020-01-24 07:28:07
问题 I want to create a finalDic which contains common keys and sum of their values myDic = [{2:1, 3:1, 5:2}, {3:4, 6:4, 2:3}, {2:5, 3:6}, ...] First find common keys commonkey = [{2:1, 3:1}, {2:3, 3:4}, {2:5, 3:6}] Then Sum and sort by their values finalDic= {3:11, 2,9} I've tried this and not even close what i want import collections myDic = [{2:1, 3:1, 5:2}, {3:4, 6:4, 2:3}, {2:5, 3:6}] def commonKey(x): i=0 allKeys = [] while i<len(x): for key in x[0].keys(): allKeys.append(key) i=i+1

Sort list of names in Python, ignoring numbers?

亡梦爱人 提交于 2020-01-24 06:09:28
问题 ['7', 'Google', '100T', 'Chrome', '10', 'Python'] I'd like the result to be all numbers at the end and the rest sorted. The numbers need not be sorted. Chrome Google Python 100T 7 10 It's slightly more complicated though, because I sort a dictionary by value. def sortname(k): return get[k]['NAME'] sortedbyname = sorted(get,key=sortname) I only added 100T after both answers were posted already, but the accepted answer still works with a slight modification I posted in a comment. To clarify, a

Sort list of names in Python, ignoring numbers?

 ̄綄美尐妖づ 提交于 2020-01-24 06:04:08
问题 ['7', 'Google', '100T', 'Chrome', '10', 'Python'] I'd like the result to be all numbers at the end and the rest sorted. The numbers need not be sorted. Chrome Google Python 100T 7 10 It's slightly more complicated though, because I sort a dictionary by value. def sortname(k): return get[k]['NAME'] sortedbyname = sorted(get,key=sortname) I only added 100T after both answers were posted already, but the accepted answer still works with a slight modification I posted in a comment. To clarify, a

Sort ArrayList<String> excluding the digits on the first half of the String

痴心易碎 提交于 2020-01-24 05:38:04
问题 I'm trying to sort an ArrayList which a series of String composed as well (XX and YY are numbers): Test: XX Genere: Maschio Eta: YY Protocollo: A I would link to sort them by only considering the YY value. I found this method but it considerers all the digits of the string and I cannot remove n digits before YY because I don't know from how many digits is composed XX: Collections.sort(strings, new Comparator<String>() { public int compare(String o1, String o2) { return extractInt(o1) -

Sorting consecutive pairs of items in a python list

﹥>﹥吖頭↗ 提交于 2020-01-24 02:08:15
问题 The data that I have is actually contained in pandas dataframe (on a column) but for the sake of this post, we extract it to get to the nub of the problem. Suppose we have a dataframe df with a column col1 which we store as a list: L = df.col1.tolist() . Now, I have about 2000 of these columns/lists and on average they have a length of about 300-400. So there is no massive need for performance here. Back to our MWE list, it is structured with items like this (ish): L = [1,2,2,1,3,3,4,4,5,5,6

Sort multigigabyte xml file

江枫思渺然 提交于 2020-01-24 00:43:09
问题 How to sort all tags in multigigabyte xml file alphabetically, all equal tags should also be sorted by attributes? All methods suggested in related questions fail for such large data. I'm looking for existing tools for Windows or Linux. 回答1: If you are using an XSLT to do the sorting, you can use the streaming-safe subset of XSLT with a streaming-enabled processor like Saxon. Saxon in streaming mode can easily manage gigabytes of input XML data. The Saxon website has very detailed

How to make this sorting program in C much faster for the large input sets

一世执手 提交于 2020-01-23 14:57:27
问题 This sort code fails for very large input file data because it takes too long for it to finish. rewind(ptr); j=0; while(( fread(&temp,sizeof(temp),1,ptr)==1) &&( j!=lines-1)) //read object by object { i=j+1; while(fread(&temp1,sizeof(temp),1,ptr)==1) //read next object , to compare previous object with next object { if(temp.key > temp1.key) //compare key value of object { temp2=temp; //if you don't want to change records and just want to change keys use three statements temp2.key =temp.key;

Best algorithm to compare two lists in python

时间秒杀一切 提交于 2020-01-23 14:33:24
问题 I have two lists (list1 and list2) in python filled with an own datatype. I want to compare these to lists and give all elements of these lists to stdout(or somewhere else), but in a specific order(without sorting the lists in any way). List1 and List2 can have elements which are not in the other list, but can also have elements which be in the other list. These elements, beeing in both lists, should output at the same line. But the elements beeing only in one list, should be in the right

Best algorithm to compare two lists in python

大城市里の小女人 提交于 2020-01-23 14:32:27
问题 I have two lists (list1 and list2) in python filled with an own datatype. I want to compare these to lists and give all elements of these lists to stdout(or somewhere else), but in a specific order(without sorting the lists in any way). List1 and List2 can have elements which are not in the other list, but can also have elements which be in the other list. These elements, beeing in both lists, should output at the same line. But the elements beeing only in one list, should be in the right

Best algorithm to compare two lists in python

血红的双手。 提交于 2020-01-23 14:30:30
问题 I have two lists (list1 and list2) in python filled with an own datatype. I want to compare these to lists and give all elements of these lists to stdout(or somewhere else), but in a specific order(without sorting the lists in any way). List1 and List2 can have elements which are not in the other list, but can also have elements which be in the other list. These elements, beeing in both lists, should output at the same line. But the elements beeing only in one list, should be in the right