Map in order range loop

If you need a map and keys in order, those are 2 different things, you need 2 different (data) types to provide that functionality. With a keys slice The easiest way to achieve this is to maintain key order in a different slice. Whenever you put a new pair into the map, first check if … Read more

Mapping 2 vectors – help to vectorize

Oh! One other option: since you’re looking for close correspondences between two sorted lists, you could go through them both simultaneously, using a merge-like algorithm. This should be O(max(length(xm), length(xn)))-ish. match_for_xn = zeros(length(xn), 1); last_M = 1; for N = 1:length(xn) % search through M until we find a match. for M = last_M:length(xm) dist_to_curr … Read more

GPS coordinates in degrees to calculate distances

Why don’t you use CLLocations distanceFromLocation: method? It will tell you the precise distance between the receiver and another CLLocation. CLLocation *locationA = [[CLLocation alloc] initWithLatitude:12.123456 longitude:12.123456]; CLLocation *locationB = [[CLLocation alloc] initWithLatitude:21.654321 longitude:21.654321]; CLLocationDistance distanceInMeters = [locationA distanceFromLocation:locationB]; // CLLocation is aka double [locationA release]; [locationB release]; It’s as easy as that.

Define a custom hash() method for use with ES6 maps

Is something like this possible? No, this is a known flaw of ES6 Collections. All they do is check for reference identity, and there is no way to change that. The best thing you can do (if hash consing the instances is not an option as you say) is not to use objects for the … Read more

Nested Dictionary to MultiIndex pandas DataFrame (3 level)

Using an example of three level dict In [1]: import pandas as pd In [2]: dictionary = {‘A’: {‘a’: {1: [2,3,4,5,6], …: 2: [2,3,4,5,6]}, …: ‘b’: {1: [2,3,4,5,6], …: 2: [2,3,4,5,6]}}, …: ‘B’: {‘a’: {1: [2,3,4,5,6], …: 2: [2,3,4,5,6]}, …: ‘b’: {1: [2,3,4,5,6], …: 2: [2,3,4,5,6]}}} And the following dictionary comprehension based on the one … Read more

I had this problem and solved it by the following 2 steps: 1) Put the following line in the application (important) element of AndroidManifest.xml file. <uses-library android:name=”com.google.android.maps” /> 2) extend MapActivity instead of Activity. enjoy!

Changing marker style in scatter plot according to third variable

The problem is that marker can only be a single value and not a list of markers, as the color parmeter. You can either do a grouping by marker value so you have the x and y lists that have the same marker and plot them: xs = [[1, 2, 3], [4, 5, 6]] ys … Read more

How to bind Dictionary to ListBox in WinForms

var choices = new Dictionary<string, string>(); choices[“A”] = “Arthur”; choices[“F”] = “Ford”; choices[“T”] = “Trillian”; choices[“Z”] = “Zaphod”; listBox1.DataSource = new BindingSource(choices, null); listBox1.DisplayMember = “Value”; listBox1.ValueMember = “Key”; (Shamelessly lifted from my own blog: Bind a ComboBox to a generic Dictionary.) This means you can use SelectedValue to get hold of the corresponding dictionary … Read more

Categories c#

Dictionary.ContainsKey return False, but a want True

You want true – but a and b are different objects. You need to override GetHashCode and Equals on class Key public class Key { string name; public Key(string n) { name = n; } public override int GetHashCode() { if (name == null) return 0; return name.GetHashCode(); } public override bool Equals(object obj) { … Read more

How to search if dictionary value contains certain string with Python

You can do it like this: #Just an example how the dictionary may look like myDict = {‘age’: [’12’], ‘address’: [’34 Main Street, 212 First Avenue’], ‘firstName’: [‘Alan’, ‘Mary-Ann’], ‘lastName’: [‘Stone’, ‘Lee’]} def search(values, searchFor): for k in values: for v in values[k]: if searchFor in v: return k return None #Checking if string ‘Mary’ … Read more