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#?
...
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 searching.
The Objective
My objective, howev...
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 suggestions? I have been working on this f...
I have some code that adds a Func<short> to a Dictionary<byte, Func<short>> 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 index being accessed is valid, it throws the exception that si...
Hi, 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()
{
for(int i=0;i<datatable.Rows...
I am trying to optimize a piece of .NET 2.0 C# code that looks like this:
Dictionary<myType, string> myDictionary = new Dictionary<myType, string>();
// some other stuff
// inside a loop check if key is there and if not add element
if(!myDictionary.ContainsKey(currentKey))
{
myDictionary.Add(currentKey, "");
}
Looks like the Dictio...
how to bind Dictionary to ListView and Text box?
namespace Models
{
public class DynamicList
{
#region Constructor
public DynamicList()
{
_propDict = new Dictionary<string, object>();
dynimicListProps = new List<DynimicListProperty>();
}
#endregion Constructor
#region Fields
private Dic...
Hi,
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 via its key?
Thanks,
Andrej
...
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 able to use underscore to define private ...
Hi,
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
...
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 of using hashtables and hashmaps versus pyt...
Hi folks,
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, "Count");
labelNumberOfNodes....
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', 'meat': 'turkey'}
I then want one big baske...
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 ?
...
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}, {'serve': False, 'open': False}, {'serve': F...
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 could look like this:
{"Data":{"fieldtype":"integer","isr...
Hi,
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
...
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:value pairs, that is, just check if it's ...
Just overriding Equals in TKey does not help.
public override bool Equals(object obj)
{ /* ... */ }
... Equals will never be called ...
... adding this doesn't help too:
public override int GetHashCode()
{
return base.GetHashCode();
}
BUT, this helps:
public override int GetHashCode()
{
return 0;
}
Now, I can look up k...
class Program
{
static void Main(string[] args)
{
var dictionary = new Dictionary<string, int>()
{
{"1", 1}, {"2", 2}, {"3", 3}
};
foreach (var s in dictionary.Keys)
{
// Throws the "Collection was modified exception..." on th...