key-value

Python 3 changing value of dictionary key in for loop not working

时间秒杀一切 提交于 2019-12-06 07:05:10
问题 I have python 3 code that is not working as expected: def addFunc(x,y): print (x+y) def subABC(x,y,z): print (x-y-z) def doublePower(base,exp): print(2*base**exp) def RootFunc(inputDict): for k,v in inputDict.items(): if v[0]==1: d[k] = addFunc(*v[1:]) elif v[0] ==2: d[k] = subABC(*v[1:]) elif v[0]==3: d[k] = doublePower(*v[1:]) d={"s1_7":[1,5,2],"d1_6":[2,12,3,3],"e1_3200":[3,40,2],"s2_13":[1,6,7],"d2_30":[2,42,2,10]} RootFunc(d) #test to make sure key var assignment works print(d) I get: {

Compound Queries with Redis

为君一笑 提交于 2019-12-06 05:57:47
问题 For learning purposes I'm trying to write a simple structured document store in Redis. In my example application I'm indexing millions of documents that look a little like the following. <book id="1234"> <title>Quick Brown Fox</title> <year>1999</year> <isbn>309815</isbn> <author>Fred</author> </book> I'm writing a little query language that allows me to say YEAR = 1999 AND TITLE="Quick Brown Fox" (again, just for my learning, I don't care that I'm reinventing the wheel!) and this should

GWAN Key-Value persistent store

☆樱花仙子☆ 提交于 2019-12-06 05:30:46
I want to use the GWAN API Key-Value to record and read a number of data (in a multi-threaded way). The problem is that my recordings are only available on the current page and therefore can not be used on my other pages. Can you show me an example or explain how to create a persistent KV store (which will be accessible on all my subdomains) ? Here is an example that I currently use: kv_t store; kv_init(&store, "users", 10, 0, 0, 0); kv_item item; item.key = "pierre"; item.klen = sizeof("pierre") - 1; item.val = "pierre@example.com"; item.flags = 0; kv_add(&store, &item); char *p = kv_get(

GPT - Non key value ads showing in key valuse ad slots

邮差的信 提交于 2019-12-06 05:26:25
I have set up Ad Units and Key Values in DFP. I have built the site with the following code based on Google's tutorials: <html lang="en"> <head> <script type="text/javascript"> var googletag = googletag || {}; googletag.cmd = googletag.cmd || []; (function() { var gads = document.createElement("script"); gads.async = true; gads.type = "text/javascript"; var useSSL = "https:" == document.location.protocol; gads.src = (useSSL ? "https:" : "http:") + "//www.googletagservices.com/tag/js/gpt.js"; var node =document.getElementsByTagName("script")[0]; node.parentNode.insertBefore(gads, node); })(); <

Object keys with NSMutableDictionary (Objective-C)

隐身守侯 提交于 2019-12-05 23:45:08
问题 I want to store a bunch of key value pairs, with the key being my own object (ObjectA) that inherits from NSObject, and the value being an int. I am trying to use an NSMutableDictionary. I understand that you can only store object types in the dictionary, so I have the following: id value = [NSNumber numberWithInt:my_number]; [[self dictionary] setObject:value forKey:myObjectA]; Now that gives me an error, saying -[ObjectA copyWithZone:]: unrecognized selector sent to instance which is fine,

Looking for an ultrafast data store to perform intersect operations

天大地大妈咪最大 提交于 2019-12-05 18:42:43
I've been using Redis for a while as a backend for Resque and now that I'm looking for a fast way to perform intersect operation on large sets of data, I decided to give Redis a shot. I've been conducting the following test: — x , y and z are Redis sets, they all contain approx. 1 million members (random integers taken from a seed array containing 3M+ members). — I want to intersect x y and z , so I'm using sintersectstore (to avoid overheating caused by data retrieval from the server to the client) sinterstore r x y z — the resulting set ( r ) contains about half a million members, Redis

Run a series of forumulae against key/value pairs stored in a java.util.List

时光总嘲笑我的痴心妄想 提交于 2019-12-05 18:04:44
Say I have a List containing components like the following: [ { "id": 1, "name": "Displacement", "value": 200 }, { "id": 2, "name":"Time", "value": 120 }, { "id":3, "name":"Mass", "value": 233 }, { "id":4, "name": "Acceleration", "value": 9.81 }, { "id": 5, "name":"Speed of Light", "value": 300000000 } ] Each component is an object of the following class: class Component { Integer id; String name; Long value; // necessary getters and setters } I need to get the following metrics from the above List: Velocity (Displacement/Time) , Force (Mass * Acceleration) and Energy (Mass * Speed of Light^2)

Android persistence alternative to SQLite

不想你离开。 提交于 2019-12-05 14:43:21
问题 Is there any other alternative to SQLite in Android for persisting data in the phone? I am looking something like iOS coredata or something simpler like a key-value store. If we need to embed it with the apps, something that is relatively small in size is also great. Thank you for your assistance. 回答1: If you need just a simple store for a couple key/value pairs, SharedPreferences is the way to go. If you are looking for something more powerful, that compares to Core Data, you should give

Python - can a dict have a value that is a list?

ε祈祈猫儿з 提交于 2019-12-05 14:32:13
问题 When using Python is it possible that a dict can have a value that is a list? for example, a dictionary that would look like the following (see KeyName3's values): { keyName1 : value1, keyName2: value2, keyName3: {val1, val2, val3} } I already know that I can use 'defaultdict' however single values are (understandably) returned as a list. The reason I ask is that my code must be generic so that the caller can retieve single key values as an item (just like from a dict key-value) and not as

Loop over object's key/value using TypeScript / Angular2 [duplicate]

送分小仙女□ 提交于 2019-12-05 12:09:53
This question already has answers here : How to get all properties values of a Javascript Object (without knowing the keys)? (22 answers) Closed 3 years ago . How can I iterate over a Object using TypeScript and being able to access key and value? My json object looks something like this: { "clients": { "123abc": { "Forename": "Simon", "Surname": "Sample" }, "456def": { "Forename": "Charlie", "Surname": "Brown" } } } The clients object to be filled is made of client models looking like: export class ClientModel { id:string; forename:string; surname:string; constructor( private id:string,