'm facing problem to sort the values based on key using dictionary object. Actually what i am storing is, each dictionary object having different data type in that dictionary all the data type taking as a string how to convert this string type to specific data type and sort it price vise, my code and out put is bellow, Please help me on this one.
-(IBAction)PriceSort:(id)sender
{
NSSortDescriptor * sort = [[NSSortDescriptor alloc] initWithKey:@"Price" ascending:true] ;
NSArray *sa = [symbolArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
NSLog(@"price=%@",sa);
}
out put {
volume = 2496752;
Yield = "10.49";
MarCap = 829;
Price = "0.715";
Symbol = SAIPI;
},
How to sort dictionary by value in Python? In Python, the dictionary class doesn't have any provision to sort items in its object. Hence, some other data structure, such as the list has to be used to be able to perform sorting. To begin with, our test data is following dictionary object having names and marks of students.
To get the value for a particular key in a dictionary, you can use the Get Dictionary Value action and specify the name of the key. To get an object’s phone value, add the Get Dictionary Value action and set it to phone. If you want the company name, you can use the dot notation company.name, as shown in the screenshot below.
The itemgetter () function returns a callable object from its operand. Finally, we shall use the dict.items () method along with the sorted () function to first obtain (marks, name) tuples and then reconstruct dictionary in a sorted order of marks.
Hence, some other data structure, such as the list has to be used to be able to perform sorting. To begin with, our test data is following dictionary object having names and marks of students.
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"price"
ascending:YES selector:@selector(localizedStandardCompare:)] ;
Please replace this one and try , hope its works .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With