key-value

Tuple list from dict in Python [duplicate]

流过昼夜 提交于 2019-12-01 02:39:24
This question already has an answer here: How can I convert a dictionary into a list of tuples? 10 answers How can I obtain a list of key-value tuples from a dict in Python? Andrew Keeton For Python 2.x only (thanks Alex): yourdict = {} # ... items = yourdict.items() See http://docs.python.org/library/stdtypes.html#dict.items for details. For Python 3.x only (taken from Alex's answer ): yourdict = {} # ... items = list(yourdict.items()) For a list of of tuples: my_dict.items() If all you're doing is iterating over the items, however, it is often preferable to use dict.iteritems() , which is

When to use “:”(colon) operator in javascript vs “=” operator?

*爱你&永不变心* 提交于 2019-12-01 02:19:43
问题 I tried looking online everywhere for past hour, but I can't seem to figure out when to use colon operator : vs = operator in javascript? From what I can tell so far, it seems when defining object properties use colon : . 回答1: The JavaScript language was built by Brandon Eich using the = sign as an assignment operator. Back in 1995, most programming languages, like Basic, Turbo Pascal, Delphi, C, C++, etc... used the same method of assigning values to variables. Rapidly creating new objects

Porting from SQLite to Redis

烂漫一生 提交于 2019-12-01 01:35:38
I was using SQLite for an app in which I used to store 8-10 columns. I used to retrieve the data based upon a combination of any number of those attributes. Now I want to port to Redis. So I was building a test app for it. But I am unable to think of how to design my redis system in such a way that I would be able to retrieve the data based upon any of those attributes. Any of you has any advice/experience? I think the best advice is to avoid sticking to the relational model when porting something from a RDBMS to Redis. And beyond the model, an important difference is to focus on data access

POST Request in Swift with key-value pairs

好久不见. 提交于 2019-12-01 00:59:08
I have to make a post request and receive a response in Swift. I need to add values to the request ​​in key-value pairs format and then I get an answer (0 or 1). I don't know how to add the Dictionary values to the request.: var url = NSURL(string:"www.myurl.com") var request = NSMutableURLRequest(URL: url!) request.HTTPMethod = "POST" var params = ["email":"\(txtEmail.text)", "passw":"\(txtPassword.text)"] as Dictionary let data = //HOW CAN I LOAD THE DATA TO THE HTTPBODY REQUEST?? request.HTTPBody = data var connection = NSURLConnection(request: request, delegate: self, startImmediately:

How do I create a definition list with d3.js?

≡放荡痞女 提交于 2019-12-01 00:08:41
I am trying to create a definition list such as this one: <dl> <dt>term1</dt> <dd>definition1</dd> <dt>term2</dt> <dd>definition2</dd> <dt>term3</dt> <dd>definition3</dd> </dl> by using a JSON in this form: { "term1":"definition1" "term1":"definition2" "term3":"definition3" } . Whch is the most elegant way to do it with d3.js ? PS: I would like to use the <dl> element because it seems the most appropriate way to semantically represent a key:value pair: http://html5doctor.com/the-dl-element/ Semantics and Structure of Name-Value Pairs Joshua Taylor Solution for d3 v3.x; no longer works as of d3

How to “convert” a Dictionary into a sequence in F#?

柔情痞子 提交于 2019-11-30 23:37:15
How do I "convert" a Dictionary into a sequence so that I can sort by key value? let results = new Dictionary() results.Add("George", 10) results.Add("Peter", 5) results.Add("Jimmy", 9) results.Add("John", 2) let ranking = results ??????? |> Seq.Sort ?????? |> Seq.iter (fun x -> (... some function ...)) A System.Collections.Dictionary<K,V> is an IEnumerable<KeyValuePair<K,V>>, and the F# Active Pattern 'KeyValue' is useful for breaking up KeyValuePair objects, so: open System.Collections.Generic let results = new Dictionary<string,int>() results.Add("George", 10) results.Add("Peter", 5)

How do I create a definition list with d3.js?

不羁的心 提交于 2019-11-30 18:13:17
问题 I am trying to create a definition list such as this one: <dl> <dt>term1</dt> <dd>definition1</dd> <dt>term2</dt> <dd>definition2</dd> <dt>term3</dt> <dd>definition3</dd> </dl> by using a JSON in this form: { "term1":"definition1" "term1":"definition2" "term3":"definition3" } . Whch is the most elegant way to do it with d3.js? PS: I would like to use the <dl> element because it seems the most appropriate way to semantically represent a key:value pair: http://html5doctor.com/the-dl-element/

Can you set a dictionary value dependant on another dictionary entry?

狂风中的少年 提交于 2019-11-30 18:06:34
问题 Here's the thought: dict1 = {key1:3, key2:5, key3:key1+key2} # so key3 relate to the value: 8 (3+5) dict1.update({key2:6}) # key3 will now relate to the value: 9 (3+6) I'm trying to avoid updating more entries than necessary as well as building new relations of key-value that's based on values that has already been calculated in a series of lookups and updates while comparing values of relations. The dictionarys' hashability is crucial to get me a more or less constant time on lookup. 回答1:

How to “convert” a Dictionary into a sequence in F#?

馋奶兔 提交于 2019-11-30 17:53:26
问题 How do I "convert" a Dictionary into a sequence so that I can sort by key value? let results = new Dictionary() results.Add("George", 10) results.Add("Peter", 5) results.Add("Jimmy", 9) results.Add("John", 2) let ranking = results ??????? |> Seq.Sort ?????? |> Seq.iter (fun x -> (... some function ...)) 回答1: A System.Collections.Dictionary<K,V> is an IEnumerable<KeyValuePair<K,V>>, and the F# Active Pattern 'KeyValue' is useful for breaking up KeyValuePair objects, so: open System.Collections

How to correctly use HashMap?

守給你的承諾、 提交于 2019-11-30 17:45:16
HashMap savedStuff = new HashMap(); savedStuff.put("symbol", this.symbol); //this is a string savedStuff.put("index", this.index); //this is an int gives me the warning: HashMap is a raw type. References to generic type HashMap<K,V> should be parameterized I'm not sure what you're trying to do, but since the example you provided uses hard-coded strings to index the data, it seems like you know what data you want to group together. If that's the case, then a Map is probably not a good choice. The better approach would be to make a class out of the commonly grouped data: public class SavedStuff