Dennis Lee Bieber wlfr...@ix.netcom.com writes:
And what real difference is that going to gain versus the existing
.get() method where the default is a sentinel?
It's just less ugly. I don't know a way to get a unique sentinel
other than sentinel = object() or something like that,
Dennis Lee Bieber wlfr...@ix.netcom.com writes:
... v = theDict.get(x, NOT_RELEVANT)
... if v is not NOT_RELEVANT:
... print x, v
I think you'd normally do this with
if x in theDict:
print x, v
but the OP was asking about a different problem, involving looking up
On Mar 26, 11:02 pm, Paul Rubin http://phr...@nospam.invalid wrote:
Dennis Lee Bieber wlfr...@ix.netcom.com writes:
... v = theDict.get(x, NOT_RELEVANT)
... if v is not NOT_RELEVANT:
... print x, v
I think you'd normally do this with
if x in theDict:
Carl Banks pavlovevide...@gmail.com writes:
if x in theDict:
print x, v
Where does v come from?
Oops, pasted from original. Meant of course print x, theDict[x].
--
http://mail.python.org/mailman/listinfo/python-list
On Mar 27, 11:20 am, Paul Rubin http://phr...@nospam.invalid wrote:
Carl Banks pavlovevide...@gmail.com writes:
if x in theDict:
print x, v
Where does v come from?
Oops, pasted from original. Meant of course print x, theDict[x].
You have look up x twice with that code,
Mudcat wrote:
I would like to use a dictionary to store byte table information to
decode some binary data. The actual number of entries won't be that
large, at most 10. That leaves the other 65525 entries as 'reserved'
or 'other' but still need to be somehow accounted for when
referenced.
Carl Banks pavlovevide...@gmail.com wrote:
On Mar 27, 11:20 am, Paul Rubin http://phr...@nospam.invalid wrote:
Carl Banks pavlovevide...@gmail.com writes:
if x in theDict:
print x, v
Where does v come from?
Oops, pasted from original. Meant of course print x,
On Mar 27, 1:06 pm, Duncan Booth duncan.bo...@invalid.invalid wrote:
Carl Banks pavlovevide...@gmail.com wrote:
On Mar 27, 11:20 am, Paul Rubin http://phr...@nospam.invalid wrote:
Carl Banks pavlovevide...@gmail.com writes:
if x in theDict:
print x, v
Where does v
andrew cooke wrote:
i don't completely follow what you are doing, but i currently use the
following to find a transition in a finite automaton for a regular
expression, and i suspect it's similar to what you want.
i get the impression the original poster went away, and maybe they just
wanted
Carl Banks pavlovevide...@gmail.com writes:
Not necessarily: if the hash calculation for x is expensive enough the
get version would still be faster.
Yeah, the get version with the special marker value is just ugly IMO,
as is the version with exceptions. Maybe there should be a two-value
I would like to use a dictionary to store byte table information to
decode some binary data. The actual number of entries won't be that
large, at most 10. That leaves the other 65525 entries as 'reserved'
or 'other' but still need to be somehow accounted for when
referenced.
So there are a couple
I would like to use a dictionary to store byte table information to
decode some binary data. The actual number of entries won't be that
large, at most 10. That leaves the other 65525 entries as 'reserved'
or 'other' but still need to be somehow accounted for when
referenced.
So there are a
Mudcat wrote:
I would like to use a dictionary to store byte table information to
decode some binary data. The actual number of entries won't be that
large, at most 10. That leaves the other 65525 entries as 'reserved'
or 'other' but still need to be somehow accounted for when
referenced.
Mudcat mnati...@gmail.com writes:
However I wondered if there was a way to simply use a range as a key
reference somehow.
Dictionaries aren't really the right structure for that. You want a
tree or binary search structure of some sort. The bisect module might
be helpful, but you will have to
An interval map maybe?
http://code.activestate.com/recipes/457411/
A programmer has to know the name of many data structures :-)
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
On Mar 26, 5:10 pm, andrew cooke and...@acooke.org wrote:
Mudcat wrote:
I would like to use a dictionary to store byte table information to
decode some binary data. The actual number of entries won't be that
large, at most 10. That leaves the other 65525 entries as 'reserved'
or 'other'
On Mar 26, 2:35 pm, Mudcat mnati...@gmail.com wrote:
I would like to use a dictionary to store byte table information to
decode some binary data. The actual number of entries won't be that
large, at most 10. That leaves the other 65525 entries as 'reserved'
or 'other' but still need to be
17 matches
Mail list logo