[Python-3000] Detecting conflicts in dict displays
Stian Soiland
stian at soiland.no
Fri Jul 28 23:57:11 CEST 2006
On 7/11/06, Terry Reedy <tjreedy at udel.edu> wrote:
> >>> d={1:'one', 1.0:'one'}
> >>> d
> {1: 'one'}
This highlights the problem. Imagine that you don't type out the
actual objects, but just receive them:
def make_dict(x, y, obj):
return {x: obj, y: obj}
x1 = x2 = "fish"
d = make_dict(x1, x2, 1337)
Here I don't really care if a and b are the same or not, I just care
that I can do d[x1] and d[x2].
(Of course this is a dangerous path to go down too deep, what about
del d[x1] ? And who would make such code, anyway?)
Maybe only for the literal values and direct variable names..?
Is the following behaviour as expected, or is it just The Lock?
import threading
count = 0
def counter():
global count
while True:
count += 1
threading.Thread(target=counter).start()
>>> {count-1+1: 1, count: 2, count-1+1: 3, count: 4, count: 5, count:
6, count: 7, count: 8, count-1+1: 9, count: 10, count: 11}
{897203081: 11}
--
Stian Søiland Any society that would give up a little
Manchester, UK liberty to gain a little security will
http://soiland.no/ deserve neither and lose both. [Franklin]
=/\=
More information about the Python-3000
mailing list