keys

Merge keys array and values array into an object in Javascript

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have: var keys = [ "height" , "width" ]; var values = [ "12px" , "24px" ]; And I'd like to convert it into this object: { height : "12px" , width : "24px" } In Python, there's the simple idiom dict(zip(keys,values)) . Is there something similar in jQuery or plain Javascript, or do I have to do this the long way? 回答1: Simple JS function would be: function toObject ( names , values ) { var result = {}; for ( var i = 0 ; i Of course you could also actually implement functions like zip, etc as JS supports higher order types which

Holding Arrow Keys Down For Character Movement C# .Net ISSUES

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So in short i'm simply trying to move a rectangle around a Canvas object in a WPF application. What i have here is my KeyDown event function. The problem is, when i hold a key down for long, it launches this function over and over again rapidly and screws up my rectangle location code. My theory/logic behind it: BECAUSE WHEN YOU HOLD A BUTTON DOWN ON A KEYBOARD IT DOES NOT MOVE SMOOTHLY (TEST IT ON THE SCROLL BAR IN YOUR BROWSER, IT STARTS, pauses, THEN CONTINUES SMOOTHLY), i want it to start a forms timer that moves the object in the UI.

Python code to read registry

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: from _winreg import * """print r"*** Reading from SOFTWARE\Microsoft\Windows\CurrentVersion\Run ***" """ aReg = ConnectRegistry(None,HKEY_LOCAL_MACHINE) aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall") for i in range(1024): try: asubkey=EnumKey(aKey,i) val=QueryValueEx(asubkey, "DisplayName") print val except EnvironmentError: break Could anyone please correct the error...i just want to display the "DisplayName" within the subkeys of the key the HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall This is the

Getting NSDictionary keys sorted by their respective values

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an NSMutableDictionary with integer values, and I'd like to get an array of the keys, sorted ascending by their respective values. For example, with this dictionary: mutableDict = { "A" = 2, "B" = 4, "C" = 3, "D" = 1, } I'd like to end up with the array ["D", "A", "C", "B"] . My real dictionary is much larger than just four items, of course. 回答1: The NSDictionary Method keysSortedByValueUsingComparator: should do the trick. You just need a method returning an NSComparisonResult that compares the object's values. Your Dictionary is

What's the difference between ES6 Map and WeakMap?

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Looking this and this MDN pages it seems like the only difference between Maps and WeakMaps is a missing "size" property for WeakMaps. But is this true? What's the difference between them? 回答1: From the very same page, section " Why Weak Map? " : The experienced JavaScript programmer will notice that this API could be implemented in JavaScript with two arrays (one for keys, one for values) shared by the 4 API methods. Such an implementation would have two main inconveniences. The first one is an O(n) search (n being the number of keys in the

What are dictionary view objects?

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: In python 2.7, we got the dictionary view methods available. Now, I know the pro and cons of the following: dict.items() (and values , keys ): returns a list, so you can actually store the result dict.iteritems() (and the like): returns a generator, so you can iterable over each value generated one by one. What are dict.viewitems() (and the like) for? What are their benefits? How does it work? What is a view after all? I read that the view is always reflecting the changes from the dictionary. But how does it behave from the perf

Python dictionary: are keys() and values() always the same order?

匿名 (未验证) 提交于 2019-12-03 02:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: It looks like the lists returned by keys() and values() methods of a dictionary are always a 1-to-1 mapping (assuming the dictionary is not altered between calling the 2 methods). For example: >>> d = {'one':1, 'two': 2, 'three': 3} >>> k, v = d.keys(), d.values() >>> for i in range(len(k)): print d[k[i]] == v[i] True True True If you do not alter the dictionary between calling keys() and calling values() , is it wrong to assume the above for-loop will always print True? I could not find any documentation confirming this. 回答1: Found this: If

How do I remove duplicate items from an array in Perl?

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an array in Perl: my @my_array = ("one","two","three","two","three"); How do I remove the duplicates from the array? 回答1: You can do something like this as demonstrated in perlfaq4 : sub uniq { my %seen; grep !$seen{$_}++, @_; } my @array = qw(one two three two three); my @filtered = uniq(@array); print "@filtered\n"; Outputs: one two three If you want to use a module, try the uniq function from List::MoreUtils 回答2: The Perl documentation comes with a nice collection of FAQs. Your question is frequently asked: % perldoc -q duplicate

C - Segmentation Fault with strcmp?

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I appear to be getting a segmentation fault somewhere with the strcmp function. I'm still very new to C and I can't see why it gives me the error. int linear_probe(htable h, char *item, int k){ int p; int step = 1; do { p = (k + step++) % h->capacity; }while(h->keys[p] != NULL && strcmp(h->keys[p], item) != 0); return p; } gdb: Program received signal SIGSEGV, Segmentation fault. 0x0000003a8e331856 in __strcmp_ssse3 () from /lib64/libc.so.6 (gdb) frame 1 #1 0x0000000000400ea6 in linear_probe (h=0x603010, item=0x7fffffffde00 "ksjojf", k=

Redis: Show database size/size for keys

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: My redis instance seems to being growing very large and I'd like to find out which of the multiple databases I have in there consumes how much memory. Redis' INFO command just shows me the total size and the number of keys per database which doesn't give me much insight... So any tools/ideas that give me more information when monitoring the redis server would be appreciated. The Redis documentation doesn't show me any commands that can return the consumed memory of certain keys, so I guess if any buggy code would write a lot of "trash" to