i am working on assignment where i define following dictionary  Dictionary&lt;string, List&lt;fileInfo&gt;&gt; myDic = new Dictionary&lt;string, List&lt;fileInfo&gt;&gt;();   where  public class fileInfo     {         public string fileFullName;         public double tf;         public double idf;         public double tf_idf;         public double cosineSim;          public fileInfo()         {             fileFullName = null;             tf = 0.0;             idf = 0.0;             tf_idf = 0.0;             cosineSim = 0.0;         }     }   now i want to sort the list with respect to COSINESIM
44281
I often have to sort a dictionary, consisting of keys &amp; values, by value. For example, I have a hash of words and respective frequencies, that I want to order by frequency.  There is a SortedList which is good for a single value (say frequency), that I want to map it back to the word.   orders by key, not value. Some resort to a , but is there a cleaner way?
87459
Basically I have a setup like the following:  Array (  [0] =&gt; Array ( [0] =&gt; stdClass Object ( [nid] =&gt; 1 [title] =&gt; title1 [uid] =&gt; 1 [parent] =&gt; 0 [weight] =&gt; -15 [name] =&gt; name1 [value] =&gt; 0 )                [1] =&gt; stdClass Object ( [nid] =&gt; 2 [title] =&gt; title2 [uid] =&gt; 1 [parent] =&gt; 0 [weight] =&gt; -7 [name] =&gt; name2 [value] =&gt; 100 )                [2] =&gt; stdClass Object ( [nid] =&gt; 3 [title] =&gt; title3 [uid] =&gt; 2 [parent] =&gt; 0 [weight] =&gt; -1 [name] =&gt; name3 [value] =&gt; 0 )                [3] =&gt; stdClass Object ( [nid] =&gt; 4 [title] =&gt; title4 [uid] =&gt; 2 [parent] =&gt; 0 [weight] =&gt; 1 [name] =&gt; name4 [value] =&gt; 80 )               )   )   What I need is a way to sort all the arrays inside the parent array by the [value] key in the Object. I've been trying for about 2 days now with usort and different methods but I just can't seem to get my head around it. The [value] key will range anywhere from 0 to 100 and I need all of the arrays sorted in decreasing order (IE: 100 down to 0).
112859
Is there a better way to do this?  string[] s = {"zero", "one", "two", "three", "four", "five"};  var x =  s .Select((a,i) =&gt; new {Value = a, Index = i}) .Where(b =&gt; b.Value.StartsWith("t")) .Select(c =&gt; c.Index);   i.e. I'm looking for a more efficient or more elegant way to get the positions of the items matching the criteria.
70423
I have a list of Line_item__c which is storing my line items as  List&lt;Line_Item__c&gt; toInsertList = new List&lt;Line_Item__c&gt;();   I am inserting these records in database using the below statement :  List&lt;Database.Saveresult&gt; insertResults=Database.insert(toInsertList, false);   Now the result is stored in insertResults which is of Database.Saveresult type but i want the result in a list of Line_Item__c. How do i do this. If anyone has a idea, it will be of great use.
80615
I am working on code generation and ran into a snag with generics. Here is a "simplified" version of what is causing me issues.  Dictionary&lt;string, DateTime&gt; dictionary = new Dictionary&lt;string, DateTime&gt;(); string text = dictionary.GetType().FullName;   With the above code snippet the value of text is as follows:   System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0,   Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.DateTime, mscorlib,   Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]   (Line breaks added for better readability.)  Is there a way to get the type name (type) in a different format without parsing the above string? I desire the following result for text:  System.Collections.Generic.Dictionary&lt;System.String, System.DateTime&gt;
24747
I've got a large array of primitive types (double). How do I sort the elements in descending order?  Unfortunately the Java API doesn't support sorting of primitive types with a Comparator.  The first approach that probably comes to mind is to convert it to a list of objects (boxing):  double[] array = new double[1048576];     Arrays.stream(array).boxed().sorted(Collections.reverseOrder())…   However, boxing each primitive in the array is too slow and causes a lot of GC pressure!  Another approach would be to sort and then reverse:  double[] array = new double[1048576]; ... Arrays.sort(array); // reverse the array for (int i = 0; i &lt; array.length / 2; i++) {      // swap the elements      double temp = array[i];      array[i] = array[array.length - (i + 1)];      array[array.length - (i + 1)] = temp; }   This approach is also slow - particularly if the array is already sorted quite well.  What's a better alternative?
44272
EDIT:  I found out that I can get it to compile if I cast the IMetadataType object to the TMetadata type.  Why do I need to do this?  EDIT #2:  The "Values" property is a .NET dictionary of type &lt;TMetadata, TData&gt;.  I have this generic method:  private void FillMetadata&lt;TMetadata, TData&gt;     (Metadata&lt;TMetadata, TData&gt; oMetadata) where TMetadata : IMetadataType {     IMetadataType o;     oMetadata.Values.Add(o, (TData)(object)GetValue()); }   I have stripped the implementation to simplify it (I actually use a real object, not the IMetadataType declared here).  My question is, why doesn't this compile?  The compile error is on the Add() method:  "cannot convert from 'IMetadataType' to 'TMetadata'."  Isn't that what the "where" clause on the method is for?  What am I missing?
17166
I have a list of integers, List&lt;Integer&gt; and I'd like to convert all the integer objects into Strings, thus finishing up with a new List&lt;String&gt;.  Naturally, I could create a new List&lt;String&gt; and loop through the list calling String.valueOf() for each integer, but I was wondering if there was a better (read: more automatic) way of doing it?
10314
The indexer into Dictionary throws an exception if the key is missing.  Is there an implementation of IDictionary that instead will return default(T)? I know about the TryGetValue() method, but that's impossible to use with LINQ. Would this efficiently do what I need?: myDict.FirstOrDefault(a =&gt; a.Key == someKeyKalue);  I don't think it will as I think it will iterate the keys instead of using a Hash lookup.
60856
I have a string that looks like this:  "Name1=Value1;Name2=Value2;Name3=Value3"   Is there a built-in class/function in Python that will take that string and construct a dictionary, as though I had done this:  dict = {     "Name1": "Value1",     "Name2": "Value2",     "Name3": "Value3" }   I have looked through the modules available but can't seem to find anything that matches.    Thanks, I do know how to make the relevant code myself, but since such smallish solutions are usually mine-fields waiting to happen (ie. someone writes: Name1='Value1=2';) etc. then I usually prefer some pre-tested function.  I'll do it myself then.
118809
I've got two columns of data I need to sort: the first column(A) needs to be sorted lexicographically and for any rows which then contain the same column A string, I need them to be sorted numerically according to what's in the second column(B).   I was thinking    'sort -f' , but that would make a '12' in column B come before a '2'.   Edit: Accidentally typed column in place of row.
1677
I've got a list of Python objects that I'd like to sort by an attribute of the objects themselves.  The list looks like:  &gt;&gt;&gt; ut [&lt;Tag: 128&gt;, &lt;Tag: 2008&gt;, &lt;Tag: &lt;&gt;, &lt;Tag: actionscript&gt;, &lt;Tag: addresses&gt;,  &lt;Tag: aes&gt;, &lt;Tag: ajax&gt; ...]   Each object has a count:  &gt;&gt;&gt; ut[1].count 1L   I need to sort the list by number of counts descending.  I've seen several methods for this, but I'm looking for best practice in Python.
18052
In a dictionary like this:  Dictionary&lt;string, string&gt; openWith = new Dictionary&lt;string, string&gt;();  openWith.Add("txt", "notepad.exe"); openWith.Add("bmp", "paint.exe"); openWith.Add("dib", "paint.exe"); openWith.Add("rtf", "wordpad.exe");  Console.WriteLine("For key = \"rtf\", value = {0}.", openWith["rtf"]);   The output is:     For Key = "rtf" value = wordpad.exe   What does the {0} mean?
92171
I am using TreeBidiMap from the  library. I want to sort this on the values which are doubles.  My method is to retrieve a Collection of the values using:    Collection coll = themap.values();   Which naturally works fine.  Main Question: I now want to know how I can convert/cast (not sure which is correct) coll into a List so it can be sorted?   I then intend to iterate over the sorted List object, which should be in order and get the appropriate keys from the TreeBidiMap (themap) using themap.getKey(iterator.next()) where the iterator will be over the list of doubles.
31151
I have a CSV file (db.txt)like this:  30.0,   0.0,    0.0 60.0,   1.9098, 5.8779 90.0,   6.9098, 9.5106 120.0,  13.09,  9.5106 150.0,  18.09,  5.8779 180.0,  20.0,   0.0   I need to typeset it. My problem is related with the wrong alignment of decimal point and the number of decimals (must be a constant for each column):  \renewcommand*{\dtlrealalign}{r}  \DTLloaddb[     noheader,     keys={x,y,theta},     headers={         \shortstack{$\boldsymbol{\theta_{2,i}}$},         \shortstack{X},         \shortstack{Y}              }   ]{db}{db.txt} \begin{table}[t]   \caption{Database file}   \centering   \DTLdisplaydb{db} \end{table}     Any advice, please?
80374
If I have this string:     2+24*48/32   what is the most efficient approach for creating this list:     ['2', '+', '24', '*', '48', '/', '32']
50233
I have built myself a generic collection class which is defined like this.   public class StatisticItemHits&lt;T&gt;{...}   This class can be used with int and string values only. However this  public class StatisticItemHits&lt;T&gt; where T : string, int {...}   won't compile. What am I doing wrong?