Все вопросы: [dictionary]

479 вопросов

10
голосов
5ответов
8237 просмотров

AS3: Check if a Dictionary is empty

Flash implements a dictionary (that is, something like a HashMap) using two approaches. One approach is the flash.utils.Dictionary class, and the other is a generic Object. I'd like to check how many key:value pairs are in the dictionary. In most cases I'd simply like to know it there are any key...

7
голосов
4ответов
17772 просмотров

Efficient way to find the largest key in a dictionary with non-zero value

I'm new Python and trying to implement code in a more Pythonic and efficient fashion. Given a dictionary with numeric keys and values, what is the best way to find the largest key with a non-zero value? Thanks

1
голосов
3ответов
3945 просмотров

Sending a Hashtable to a Webservice

Im trying to send a List of Items with generic Keys and Value Types to a asp.net webservice. How can i do this? I tried it with List<Dictionary<String, String>>, but this doens't work. I do not get an exception, but when i break in the webserivice, my collection is null. The Data coul...

1
голосов
2ответов
2126 просмотров

How to strip a list of tuple with python?

I have an array with some flag for each case. In order to use print the array in HTML and use colspan, I need to convert this : [{'serve': False, 'open': False}, {'serve': False, 'open': False}, {'serve': False, 'open': False}, {'serve': False, 'open': False}, {'serve': False, 'open': False}, {'...

0
голосов
3ответов
159 просмотров

How to generate a list of 150 cases initialised with a dict in Python?

I would like to create a list like this list = [] for i in range(150): list.append({'open': False, 'serve': False}) But is there a better way in Python to do it ?

18
голосов
2ответов
4296 просмотров

How can 2 Python dictionaries become 1?

Possible Duplicate: Python “extend” for a dictionary I know that Python list can be appended or extended. Is there an easy way to combine two Python dictionaries with unique keys, for instance: basket_one = {'fruit': 'watermelon', 'veggie': 'pumpkin'} basket_two = {'dairy': 'cheese', '...

1
голосов
1ответов
832 просмотров

Binding Dictionary.Keys.Count to a Label

I have a Dictionary and want to display the number of items in this dictionary with a Label, without updating the label manually each time I add or remove an item from the dictionary. I tried it with the Binding class: Binding bindingNodeCount = new Binding("Text", _graphDisplay.data.nodes.Keys...

44
голосов
6ответов
30658 просмотров

Why Can't I store references in a `std::map` in C++?

I understand that references are not pointers, but an alias to an object. However, I still don't understand what exactly this means to me as a programmer, i.e. what are references under the hood? I think the best way to understand this would be to understand why it is I can't store a reference ...

93
голосов
4ответов
65225 просмотров

Java Equivalent to Python Dictionaries

I am a long time user of Python and really like the way that the dictionaries are used. They are very intuitive and easy to use. Is there a good Java equivalent to python's dictionaries? I have heard of people using hashmaps and hashtables. Could someone explain the similarities and differences o...

5
голосов
2ответов
1964 просмотров

c# - Why can't my Dictionary class see the ToArray() method?

I see in the API Dictionary has a ToArray() method (in the extension classes area), but when I try to use this from my Dictionary instance it can't see it??? How do I "enable" ToArray() for my Dictionary instance? Thanks

1
голосов
1ответов
5885 просмотров

Dictionary Property in VBA Class

I have been asked to modify an Excel sheet with some arcaic programming. I have decided to rewrite it rather then modify all of the many GOTO statments and static arrays. My background is in C# so it has been a bit of a challenge (note: I am sure the naming convention is bad, I am used to being...

7
голосов
6ответов
8207 просмотров

Does the length of key affect Dictionary performance?

I will use a Dictionary in a .NET project to store a large number of objects. Therefore I decided to use a GUID-string as a key, to ensure unique keys for each object. Does a large key such as a GUID (or even larger ones) decrease the performance of a Dictionary, e.g. for retrieving an object vi...

3
голосов
1ответов
11488 просмотров

WPF binding Dictionary<string list> to listView, ListBox how?</string>

how to bind Dictionary to ListView and Text box? namespace Models { public class DynamicList { #region Constructor public DynamicList() { _propDict = new Dictionary&lt;string, object&gt;(); dynimicListProps = new List&lt;DynimicListProperty&gt;(); } #endr...

2
голосов
5ответов
3610 просмотров

Help with C#.NET generic collections performance and optimization

I am trying to optimize a piece of .NET 2.0 C# code that looks like this: Dictionary&lt;myType, string&gt; myDictionary = new Dictionary&lt;myType, string&gt;(); // some other stuff // inside a loop check if key is there and if not add element if(!myDictionary.ContainsKey(currentKey)) { myDic...

0
голосов
3ответов
2453 просмотров

C# code optimization for accessing datatable records

i have a cost issue with datatable. And i need to replace the code with a smarter one. i have a datatable and the sample values are like this: Columns : id, user_id, starttime, endtime Row Sample : 1 , 5, 05.10.2009 08:00:00,05.10.2009 17:00 my pseudo code is function something() ...

0
голосов
2ответов
231 просмотров

Dictionary&lt;&gt; is reporting invalid key when it's not

I have some code that adds a Func&lt;short&gt; to a Dictionary&lt;byte, Func&lt;short&gt;&gt; at index 0. Later on, some code within the class that contains the dictionary attempts to extract this Func (via TryGetValue) and execute it, throwing an exception if it does not work. Even though the in...

0
голосов
2ответов
260 просмотров

iPhone properties getting set to nil

I set a property with this declaration: @property (nonatomic,retain) NSDictionary *itemData; to a dictionary with 1 key - val pair. The table view in my view then gets the one value for the dictionary fine as a section header. But when I go back to access that very same value, it is nil. Any ...

0
голосов
1ответов
438 просмотров

Including Large Wordlist in Stand-alone Dictionary Application

The Application I'm working on a simple dictionary search tool, with the main purpose of searching a word-list of around 180,000 words. To begin with, the word-list was a plain-text document, with each word on a single line. Upon loading, the word-list was processed into a simple array for sea...

4
голосов
5ответов
3094 просмотров

C#: Does a dictionary in C# have something similar to the Python setdefault?

Trying to translate some methods written in Python over into C#. The line looks like this: d[p] = d.setdefault(p, 0) + 1 What exactly does setdefault do? And is there anything similar I can use in a C# dictionary? Or rather, how can I translate that line into C#?

3
голосов
2ответов
1426 просмотров

KeyError with dict.fromkeys() and dict-like object

In Python, you can use a dictionary as the first argument to dict.fromkeys(), e.g.: In [1]: d = {'a': 1, 'b': 2} In [2]: dict.fromkeys(d) Out[2]: {'a': None, 'b': None} I tried to do the same with a dict-like object, but that always raises a KeyError, e.g.: In [1]: class SemiDict: ...: ...

23
голосов
3ответов
35785 просмотров

How to bind Dictionary to ListBox in WinForms

It is possible to bind a Dictionary to a Listbox, keeping in sync between the Listbox and the member property?

31
голосов
11ответов
9776 просмотров

How to implement a multi-index dictionary?

Basically I want something like Dictionary, but not (as I've seen here in other question) with the keys in AND, but in OR. To better explain: I want to be able to find an element in the dictionary providing just one of the keys, not both. I also think we should consider thread-safety and the abi...

43
голосов
10ответов
85751 просмотров

C# Dictionary with two Values per Key?

I have a situation in code where a Dictionary&lt;string, string&gt; seemed like the best idea - I need a collection of these objects and I need them to be accessible via a unique key. Exactly what the Dictionary concept is for, right? Well, the requirements have expanded to the point where I now...

2
голосов
3ответов
1772 просмотров

Problem using map with a list of lists in Haskell

I am using Haskell to solve problem 99 in euler project, where I must find the maximum result from a list of base exponent pairs. I came up with this: prob99 = maximum $ map ((fst)^(snd)) numbers Where the numbers are in the form: numbers = [[519432,525806],[632382,518061],[78864,613712].. ...

20
голосов
5ответов
20207 просмотров

Combining Dictionaries Of Lists In Python

I have a very large collection of (p, q) tuples that I would like to convert into a dictionary of lists where the first item in each tuple is a key that indexes a list that contains q. Example: Original List: (1, 2), (1, 3), (2, 3) Resultant Dictionary: {1:[2, 3], 2:[3]} Furthermore, I ...

586
голосов
15ответов
450459 просмотров

How to define hash tables in Bash?

What is the equivalent of Python dictionaries but in Bash (should work across OS X and Linux).

6
голосов
7ответов
3864 просмотров

Mapping std::map to Python

Sometimes it makes sense to have a key-ordered dictionary. In C++, this is often implemented with a Red-black tree. But any self-balancing binary search tree will do (fwiw, Knuth is particularly clear on this subject). The best solution I've been able to come up with so far is to take R. McGraw's...

0
голосов
1ответов
898 просмотров

Can you programmatically look up a word in the Mac OS's built-in dictionary?

I'd like to have a program of mine retrieve a definition of a word. Is there a way to access the built-in dictionary using Objective-C? (i.e. the one that Dictionary.app and command-control-D use)

2
голосов
6ответов
426 просмотров

Return a list of dictionaries that match the corresponding list of values in python

For example, this is my list of dictionaries: [{'name': 'John', 'color': 'red' }, {'name': 'Bob', 'color': 'green'}, {'name': 'Tom', 'color': 'blue' }] Based on the list ['blue', 'red', 'green'] I want to return the following: [{'name': 'Tom', 'color': 'blue' }, {'name': 'John', 'col...

1
голосов
3ответов
3345 просмотров

How to split string into a Dictionary<string></string>

I need to create an dictionary by splitting a string like this: [SenderName] Some name [SenderEmail] Some email address [ElementTemplate] Some text for an element [BodyHtml] This will contain the html body text in multi lines [BodyText] This will be multiline for text body The key could be su...