I guess another way to phrase this would be "Is there a class like List<> in C#, but optimized for checking whether a particular value is present?" I'm sure for a small set of values List<>.Contains would probably be fine, but what if I have a set of thousands or millions of values and wanted to find out whether a certain value was in it...
I don't understand how to loop over a static dictionary contained in a static class from my aspx page. I have this for the static class
public static class ErrorCode
{
public static IDictionary<int, string> ErrorCodeDic;
static ErrorCode()
{
ErrorCodeDic = new Dictionary<int, string>()
{
{1, ...
I have a need for some kind of information that is in essence static. There is not much of this information, but alot of objects will use that information.
Since there is not a lot of that information (few dictionaries and some lists), I thought that I have 2 options - create models for holding that information in the database or write ...
I have a simple problem that i cannot solve. I have a dictionary:
aa = {'ALA':'A'}
test = 'ALA'
I'm have trouble writing code where that value from test is taken and referenced in the dictionary aa and 'A' is printed.
I'm assuming i would have to use a for loop? something like...
for i in test:
if i in aa:
print i
I un...
I have text documents like the following which contain single and multiple variables:
title:: Report #3
description:: This is the description.
note:: more information is available from marketing
note:: time limit for this project is 18 hours
todo:: expand the outline
todo:: work on the introduction
todo:: lookup footnotes
I need to it...
Is there a way to see how many items in a dictionary share the same value in Python?
Let's say that I have a dictionary like:
{"a": 600, "b": 75, "c": 75, "d": 90}
I'd like to get a resulting dictionary like:
{600: 1, 75: 2, 90: 1}
My first naive attempt would be to just use a nested-for loop and for each value then I would iterat...
I have a dictionary as follows:
{'A':0,'C':0,'G':0,'T':0}
I want to create an array with many dictionaries in it, as follows:
[{'A':0,'C':0,'G':0,'T':0},{'A':0,'C':0,'G':0,'T':0},{'A':0,'C':0,'G':0,'T':0},{'A':0,'C':0,'G':0,'T':0},...]
This is my code:
weightMatrix = []
for k in range(motifWidth):
weightMatrix[k] = {'A':0,'C':0,...
I made a Dictionary<string, string> collection so that I can quickly reference the items by their string identifier.
But I now also need to access this collective by index counter (foreach won't work in my real example).
What do I have to do to the collection below so that I can access its items via integer index as well?
using Syste...
Hi
I have a piece of code that does not seem to do what it is expected to do. VBA Arrays are mutable by all means, but it seems that when they are stored into a Dictionary as values of some keys, they are not mutable anymore. Any ideas?
Sub foo()
Dim mydict As New Dictionary
mydict.Add "A", Array(1, 2, 3)
MsgBox mydict("A"...
While other questions have tackled the broader category of sequences and modules, I ask this very specific question:
"What naming convention do you use for dictionaries and why?"
Some naming convention samples I have been considering:
# 'value' is the data type stored in the map, while 'key' is the type of key
value_for_key={key1:valu...
If I wanted to have a collection that described the (recursive) contents of a root directory, including directories and files, how would I store them? Or do I need to come up with an object that holds:
-Current directory
-Parent directory
-Files in directory
..and slap them all in one big list and manually work out the relationship at r...
Hi,
I have a dictionary with around 1 milions items. I am constantly looping throw the dictionnary :
public void DoAllJobs()
{
foreach (KeyValuePair<uint, BusinessObject> p in _dictionnary)
{
if(p.Value.MustDoJob)
p.Value.DoJob();
}
}
The execution is...
Background: Professional tools developer. SQL/DB amateur.
Setup: .Net 3.5 winforms app talking to MS SQL Server 2008.
Scenario: I am populating a database with information extracted from a large quantity of files. This amounts to about 60M records, each of which has an arbitrarily sized message associated with it. My original plan w...
I have a list of dictionaries that I get back from a web service call.
listA = [{'name':'foo', 'val':'x'},
{'name':'bar', 'val':'1'},
{'name':'alice','val':'2'}]
I need to compare results from the previous call to the service and pull out changes. so on next call I may get:
listB = [{'name':'foo', 'val':'y'},
...
def sortProfiles(p):
return sorted(p, key=itemgetter('first_name'))
I have a list with dictionaries. This function allows me to sort them by their first_name. However, it's case-sensitive.
...
How to sort the following dictionary by the value of "remaining_pcs" or "discount_ratio"?
promotion_items = {
'one': {'remaining_pcs': 100, 'discount_ratio': 10},
'two': {'remaining_pcs': 200, 'discount_ratio': 20},
}
EDIT
What I mean is getting a sorted list of above dictionary, not to sort the dictionary itself.
...
Cocoa provides NSDictionary, which essentially is an associative array.
Is there a nice way to get bidirectional associativity? i.e. one way would have been if NSDictionary had a keyForObject: method which mirrored the behavior of objectForKey:.
I don't really care if NSDictionary is not the way to get this. I know NSDictionary does pr...
I have a list of objects and I need to find an object as quickly as possible (by it's name property). What data-structure should I use? I know I can use a Dictionary, but there wont ever be more than 10 items in the list, and if I remember correctly the dictionary is implemented as an array if the collection contains 10 items or less.
T...
I am trying to round up cases when it makes sense to use a map (set of key-value entries). So far I have two categories (see below). Assuming more exist, what are they?
Please limit each answer to one unique category and put up an example.
Property values (like a bean)
age -> 30
sex -> male
loc -> calgary
Presence, with O(1) pe...
Im new two python and am trying to grow a dictionary of dictionaries. I have done this in php and perl but python is behaving very differently. Im sure it makes sense to those more familiar with python. Here is my code:
colnames = ['name','dob','id'];
tablehashcopy = {};
tablehashcopy = dict.fromkeys(colnames,{});
tablehashcopy['name']...