Sometimes I define a
System.Collections.Generic.Dictionary(Of Key, ...)
but actually I only use the Key part. Is there any collection which I
can use
which is similar to a Dictionary, but without the value part ?
I mean just a list of unique key Object , with a O(1) retrieval
operation ?
-Pam 4 2625
All collections have value parts. If your keys are strings, use
System.Collections.Specialized.StringCollection. Otherwise, try
dim Valueless as new Dictionary(of KeyType, KeyType)
Valueless.add(key, key)
At least this way you don't have two objects floating around memory - just
one with two references.
Mike Ober.
"pamela fluente" <pa***********@libero.itwrote in message
news:11**********************@v45g2000cwv.googlegr oups.com...
>
Sometimes I define a
System.Collections.Generic.Dictionary(Of Key, ...)
but actually I only use the Key part. Is there any collection which I
can use
which is similar to a Dictionary, but without the value part ?
I mean just a list of unique key Object , with a O(1) retrieval
operation ?
-Pam
On Feb 13, 12:03 am, "pamela fluente" <pamelaflue...@libero.itwrote:
Sometimes I define a
System.Collections.Generic.Dictionary(Of Key, ...)
but actually I only use the Key part. Is there any collection which I
can use
which is similar to a Dictionary, but without the value part ?
I mean just a list of unique key Object , with a O(1) retrieval
operation ?
-Pam
I'm particularly fond of
System.Collections.ObjectModel.KeyedCollection(Of Key, Item). It's
usefull when the item is also the key, or the key is a property of the
item itself. Unfortunately its an abstract class, which means you must
inherit it, because there's a GetKeyForItem method that needs
implementation. Indexed access is O(1), while keyed access is near
O(1) -- or so the docs say. Besides, it has the definite advantage (to
me) that it keeps the insertion order (which a Dictionary won't).
HTH.
Regards,
Branco.
On 13 Feb, 04:50, "Michael D. Ober" <obermd.@.alum.mit.edu.nospam>
wrote:
All collections have value parts. If your keys are strings, use
System.Collections.Specialized.StringCollection.
The times I need keys only are often those where the object is also
used as a key (through an appropriate comparer).
Otherwise, try
>
dim Valueless as new Dictionary(of KeyType, KeyType)
Valueless.add(key, key)
Yes that's what I am doing. Or else I do Valueless.add(key, Nothing)
(is this better?) which anyway seems quite awkward to me.
>
At least this way you don't have two objects floating around memory - just
one with two references.
Mike Ober.
On 13 Feb, 06:45, "Branco Medeiros" <branco.medei...@gmail.comwrote:
On Feb 13, 12:03 am, "pamela fluente" <pamelaflue...@libero.itwrote:
Sometimes I define a
System.Collections.Generic.Dictionary(Of Key, ...)
but actually I only use the Key part. Is there any collection which I
can use
which is similar to a Dictionary, but without the value part ?
I mean just a list of unique key Object , with a O(1) retrieval
operation ?
-Pam
I'm particularly fond of
System.Collections.ObjectModel.KeyedCollection(Of Key, Item). It's
usefull when the item is also the key, or the key is a property of the
item itself. Unfortunately its an abstract class, which means you must
inherit it, because there's a GetKeyForItem method that needs
implementation. Indexed access is O(1), while keyed access is near
O(1) -- or so the docs say. Besides, it has the definite advantage (to
me) that it keeps the insertion order (which a Dictionary won't).
Hmm I might give it a try. Isn't strange that there isn't a collection
of keys only ? I think it could be nice to have it
>
HTH.
Regards,
Branco.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: none |
last post by:
or is it just me?
I am having a problem with using a dictionary as an attribute of a
class. This happens in python 1.5.2 and 2.2.2 which I am accessing
through pythonwin builds 150 and 148...
|
by: Elbert Lev |
last post by:
Hi!
Here is the problem:
I have a dictionary. Keys are strings. How to make dictionary lookup
case insensitive?
In other words:
If dict = {'First":"Bob", "Last":"Tom"}, dict should return...
|
by: Egor Bolonev |
last post by:
why functions created with lambda forms cannot contain statements?
how to get unnamed function with statements?
|
by: Raymond Hettinger |
last post by:
I would like to get everyone's thoughts on two new dictionary methods:
def count(self, value, qty=1):
try:
self += qty
except KeyError:
self = qty
def appendlist(self, key, *values):
try:
|
by: Christoph Zwerschke |
last post by:
Ok, the answer is easy: For historical reasons - built-in sets exist
only since Python 2.4.
Anyway, I was thinking about whether it would be possible and desirable
to change the old behavior in...
|
by: rudysanford |
last post by:
I just started messing with programming and started with Python. Part
of my first project deals with translating numerical values to letters.
I would like to be able to do the reverse as well,...
|
by: vatamane |
last post by:
This has been bothering me for a while. Just want to find out if it
just me or perhaps others have thought of this too: Why shouldn't the
keyset of a dictionary be represented as a set instead of a...
|
by: Marko.Cain.23 |
last post by:
Hi,
I create a dictionary like this
myDict = {}
and I add entry like this:
myDict = 1
but how can I empty the whole dictionary?
Thank you.
|
by: Bob Altman |
last post by:
Hi all,
I'm trying to do something that should be really easy, but I can't think of an
obvious way to do it. I have a dictionary whose value is a "value type" (as
opposed to a reference type --...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |